File tree Expand file tree Collapse file tree 2 files changed +10
-3
lines changed Expand file tree Collapse file tree 2 files changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -68,6 +68,7 @@ Options object:
68
68
| ` fileStoreName ` | string | Customize the store name |
69
69
| ` lockDbName ` | string | Customize the database name for the lock mutex |
70
70
| ` lockStoreName ` | string | Customize the store name for the lock mutex |
71
+ | ` defer ` | boolean = false | If true, avoids mutex contention during initialization |
71
72
72
73
#### Advanced usage
73
74
Original file line number Diff line number Diff line change @@ -77,6 +77,7 @@ module.exports = class PromisifiedFS {
77
77
fileStoreName = name + "_files" ,
78
78
lockDbName = name + "_lock" ,
79
79
lockStoreName = name + "_lock" ,
80
+ defer = false ,
80
81
} = { } ) {
81
82
await this . _gracefulShutdown ( )
82
83
this . _name = name
@@ -93,9 +94,14 @@ module.exports = class PromisifiedFS {
93
94
this . _initPromiseResolve ( ) ;
94
95
this . _initPromiseResolve = null ;
95
96
}
96
- // The fs is initially activated when constructed (in order to wipe/save the superblock)
97
- // This is not awaited, because that would create a cycle.
98
- this . stat ( '/' )
97
+ // The next comment starting with the "fs is initially activated when constructed"?
98
+ // That can create contention for the mutex if two threads try to init at the same time
99
+ // so I've added an option to disable that behavior.
100
+ if ( ! defer ) {
101
+ // The fs is initially activated when constructed (in order to wipe/save the superblock)
102
+ // This is not awaited, because that would create a cycle.
103
+ this . stat ( '/' )
104
+ }
99
105
}
100
106
async _gracefulShutdown ( ) {
101
107
if ( this . _operations . size > 0 ) {
You can’t perform that action at this time.
0 commit comments