@@ -3,14 +3,16 @@ const locks = new Map<any, Map<string, Promise<any>>>();
33/**
44 * Only allow one instance of the callback to run at a time for a given `scope` and `key`.
55 */
6- export async function withLock < ReturnType > ( scope : any , key : string , callback : ( ) => Promise < ReturnType > ) : Promise < ReturnType > ;
7- export async function withLock < ReturnType > (
8- scope : any , key : string , acquireLockSignal : AbortSignal | undefined , callback : ( ) => Promise < ReturnType >
6+ export async function withLock < ReturnType , const ScopeType = any > (
7+ scope : ScopeType , key : string , callback : ( this : ScopeType ) => Promise < ReturnType >
98) : Promise < ReturnType > ;
10- export async function withLock < ReturnType > (
11- scope : any ,
9+ export async function withLock < ReturnType , const ScopeType = any > (
10+ scope : ScopeType , key : string , acquireLockSignal : AbortSignal | undefined , callback : ( this : ScopeType ) => Promise < ReturnType >
11+ ) : Promise < ReturnType > ;
12+ export async function withLock < ReturnType , const ScopeType = any > (
13+ scope : ScopeType ,
1214 key : string ,
13- acquireLockSignalOrCallback : AbortSignal | undefined | ( ( ) => Promise < ReturnType > ) ,
15+ acquireLockSignalOrCallback : AbortSignal | undefined | ( ( this : ScopeType ) => Promise < ReturnType > ) ,
1416 callback ?: ( ) => Promise < ReturnType >
1517) : Promise < ReturnType > {
1618 let acquireLockSignal : AbortSignal | undefined = undefined ;
@@ -47,7 +49,7 @@ export async function withLock<ReturnType>(
4749 throw acquireLockSignal . reason ;
4850 }
4951
50- const promise = callback ( ) ;
52+ const promise = callback . call ( scope ) ;
5153
5254 if ( ! locks . has ( scope ) )
5355 locks . set ( scope , new Map ( ) ) ;
0 commit comments