File tree Expand file tree Collapse file tree 1 file changed +4
-8
lines changed
Expand file tree Collapse file tree 1 file changed +4
-8
lines changed Original file line number Diff line number Diff line change 77export class Mutex {
88 static Guard = class Guard {
99 #mutex: Mutex ;
10- #onRelease?: ( ) => void ;
11- constructor ( mutex : Mutex , onRelease ?: ( ) => void ) {
10+ constructor ( mutex : Mutex ) {
1211 this . #mutex = mutex ;
13- this . #onRelease = onRelease ;
1412 }
1513 dispose ( ) : void {
16- this . #onRelease?.( ) ;
1714 return this . #mutex. release ( ) ;
1815 }
1916 } ;
@@ -22,17 +19,15 @@ export class Mutex {
2219 #acquirers: Array < ( ) => void > = [ ] ;
2320
2421 // This is FIFO.
25- async acquire (
26- onRelease ?: ( ) => void ,
27- ) : Promise < InstanceType < typeof Mutex . Guard > > {
22+ async acquire ( ) : Promise < InstanceType < typeof Mutex . Guard > > {
2823 if ( ! this . #locked) {
2924 this . #locked = true ;
3025 return new Mutex . Guard ( this ) ;
3126 }
3227 const { resolve, promise} = Promise . withResolvers < void > ( ) ;
3328 this . #acquirers. push ( resolve ) ;
3429 await promise ;
35- return new Mutex . Guard ( this , onRelease ) ;
30+ return new Mutex . Guard ( this ) ;
3631 }
3732
3833 release ( ) : void {
@@ -44,3 +39,4 @@ export class Mutex {
4439 resolve ( ) ;
4540 }
4641}
42+
You can’t perform that action at this time.
0 commit comments