@@ -57,8 +57,6 @@ module.exports = class PromisifiedFS {
57
57
this . backFile = this . _wrap ( this . backFile , cleanParamsFilepathOpts , true )
58
58
this . du = this . _wrap ( this . du , cleanParamsFilepathOpts , false ) ;
59
59
60
- this . _backend = options . backend || new DefaultBackend ( ) ;
61
-
62
60
this . _deactivationPromise = null
63
61
this . _deactivationTimeout = null
64
62
this . _activationPromise = null
@@ -76,8 +74,15 @@ module.exports = class PromisifiedFS {
76
74
}
77
75
async _init ( name , options = { } ) {
78
76
await this . _gracefulShutdown ( ) ;
77
+ if ( this . _activationPromise ) await this . _deactivate ( )
79
78
80
- await this . _backend . init ( name , options ) ;
79
+ if ( this . _backend && this . _backend . destroy ) {
80
+ await this . _backend . destroy ( ) ;
81
+ }
82
+ this . _backend = options . backend || new DefaultBackend ( ) ;
83
+ if ( this . _backend . init ) {
84
+ await this . _backend . init ( name , options ) ;
85
+ }
81
86
82
87
if ( this . _initPromiseResolve ) {
83
88
this . _initPromiseResolve ( ) ;
@@ -130,12 +135,17 @@ module.exports = class PromisifiedFS {
130
135
}
131
136
if ( this . _deactivationPromise ) await this . _deactivationPromise
132
137
this . _deactivationPromise = null
133
- if ( ! this . _activationPromise ) this . _activationPromise = this . _backend . activate ( ) ;
138
+ if ( ! this . _activationPromise ) {
139
+ this . _activationPromise = this . _backend . activate ? this . _backend . activate ( ) : Promise . resolve ( ) ;
140
+ }
134
141
await this . _activationPromise
135
142
}
136
143
async _deactivate ( ) {
137
144
if ( this . _activationPromise ) await this . _activationPromise
138
- if ( ! this . _deactivationPromise ) this . _deactivationPromise = this . _backend . deactivate ( ) ;
145
+
146
+ if ( ! this . _deactivationPromise ) {
147
+ this . _deactivationPromise = this . _backend . deactivate ? this . _backend . deactivate ( ) : Promise . resolve ( ) ;
148
+ }
139
149
this . _activationPromise = null
140
150
if ( this . _gracefulShutdownResolve ) this . _gracefulShutdownResolve ( )
141
151
return this . _deactivationPromise
0 commit comments