File tree Expand file tree Collapse file tree 1 file changed +20
-21
lines changed Expand file tree Collapse file tree 1 file changed +20
-21
lines changed Original file line number Diff line number Diff line change 1- const Lock = ( ) => {
2- return {
3- lockQueue : new Array ( ) ,
4- locked : false
1+ class AWaitLock {
2+ constructor ( ) {
3+ this . lockQueue = [ ] ;
4+ this . locked = false ;
55 }
6- }
76
8- const acquire = async ( lock ) => {
9- if ( lock . locked ) {
10- let that = lock ;
11- await new Promise ( ( resolve ) => {
12- that . lockQueue . push ( resolve ) ;
13- } ) ;
7+ async acquire ( ) {
8+ if ( this . locked ) {
9+ let that = this ;
10+ await new Promise ( ( resolve ) => {
11+ that . lockQueue . push ( resolve ) ;
12+ } ) ;
13+ }
14+ this . locked = true ;
15+ return true ;
1416 }
15- lock . locked = true ;
16- return true ;
17- } ;
18-
1917
20- const release = ( lock ) => {
21- lock . locked = false ;
22- const resolve = lock . lockQueue . pop ( ) ;
23- if ( resolve ) {
24- resolve ( ) ;
18+ release ( ) {
19+ this . locked = false ;
20+ let resolve = this . lockQueue . pop ( ) ;
21+ if ( resolve ) {
22+ resolve ( ) ;
23+ }
2524 }
2625}
2726
28- export { Lock , acquire , release } ;
27+ export default AWaitLock ;
You can’t perform that action at this time.
0 commit comments