File tree Expand file tree Collapse file tree 1 file changed +7
-4
lines changed
Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change 11import fsPromises from 'fs/promises' ;
22import { InternalServerOptions } from "../../types" ;
33
4+ const mtimeUpdateIntervalTime = 2_000
5+ const mtimeLimit = 10_000
6+
47export async function waitForLock ( path : string , options : InternalServerOptions ) : Promise < void > {
58 const lockPath = `${ path } .lock`
69 let retries = 0 ;
7-
10+
811 do {
912 retries ++ ;
1013 try {
1114 const stat = await fsPromises . stat ( lockPath )
12- if ( performance . now ( ) - stat . mtime . getTime ( ) > 10_000 ) {
15+ if ( performance . now ( ) - stat . mtime . getTime ( ) > mtimeLimit ) {
1316 return
1417 } else {
1518 await new Promise ( resolve => setTimeout ( resolve , options . lockRetryWait ) )
@@ -32,7 +35,7 @@ function setupMTimeEditor(lockPath: string): () => Promise<void> {
3235 const time = performance . now ( ) ;
3336 await fsPromises . utimes ( lockPath , time , time )
3437 } catch { }
35- } , 2_000 )
38+ } , mtimeUpdateIntervalTime )
3639
3740 return async ( ) => {
3841 clearInterval ( interval )
@@ -48,7 +51,7 @@ export async function lockFile(path: string): Promise<() => Promise<void>> {
4851 } catch ( e ) {
4952 if ( e . code === 'EEXIST' ) {
5053 const stat = await fsPromises . stat ( lockPath )
51- if ( performance . now ( ) - stat . mtime . getTime ( ) > 10_000 ) {
54+ if ( performance . now ( ) - stat . mtime . getTime ( ) > mtimeLimit ) {
5255 return setupMTimeEditor ( lockPath )
5356 } else {
5457 throw 'LOCKED'
You can’t perform that action at this time.
0 commit comments