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:
6868| ` fileStoreName ` | string | Customize the store name |
6969| ` lockDbName ` | string | Customize the database name for the lock mutex |
7070| ` lockStoreName ` | string | Customize the store name for the lock mutex |
71+ | ` defer ` | boolean = false | If true, avoids mutex contention during initialization |
7172
7273#### Advanced usage
7374
Original file line number Diff line number Diff line change @@ -77,6 +77,7 @@ module.exports = class PromisifiedFS {
7777 fileStoreName = name + "_files" ,
7878 lockDbName = name + "_lock" ,
7979 lockStoreName = name + "_lock" ,
80+ defer = false ,
8081 } = { } ) {
8182 await this . _gracefulShutdown ( )
8283 this . _name = name
@@ -93,9 +94,14 @@ module.exports = class PromisifiedFS {
9394 this . _initPromiseResolve ( ) ;
9495 this . _initPromiseResolve = null ;
9596 }
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+ }
99105 }
100106 async _gracefulShutdown ( ) {
101107 if ( this . _operations . size > 0 ) {
You can’t perform that action at this time.
0 commit comments