File tree Expand file tree Collapse file tree 3 files changed +13
-11
lines changed Expand file tree Collapse file tree 3 files changed +13
-11
lines changed Original file line number Diff line number Diff line change @@ -17,8 +17,8 @@ class Pool {
17
17
item = this . items [ this . current ] ;
18
18
free = this . free [ this . current ] ;
19
19
this . current ++ ;
20
+ if ( this . current === this . size ) this . current = 0 ;
20
21
} while ( ! item || ! free ) ;
21
- if ( this . current === this . size ) this . current = 0 ;
22
22
return item ;
23
23
}
24
24
Original file line number Diff line number Diff line change @@ -23,8 +23,8 @@ class Pool {
23
23
item = this . items [ this . current ] ;
24
24
free = this . free [ this . current ] ;
25
25
this . current ++ ;
26
+ if ( this . current === this . size ) this . current = 0 ;
26
27
} while ( ! item || ! free ) ;
27
- if ( this . current === this . size ) this . current = 0 ;
28
28
return item ;
29
29
}
30
30
@@ -62,10 +62,12 @@ class Pool {
62
62
63
63
( async ( ) => {
64
64
const pool = new Pool ( ) ;
65
- pool . add ( { item : 1 } ) ;
66
- pool . add ( { item : 2 } ) ;
67
- const last = { item : 3 } ;
68
- pool . add ( last ) ;
65
+ const item1 = { item : 1 }
66
+ pool . add ( item1 ) ;
67
+ const item2 = { item : 2 }
68
+ pool . add ( item2 ) ;
69
+ const item3 = { item : 3 } ;
70
+ pool . add ( item3 ) ;
69
71
70
72
const x1 = await pool . capture ( ) ;
71
73
console . log ( { x1 } ) ;
@@ -84,7 +86,7 @@ class Pool {
84
86
console . log ( { x6 } ) ;
85
87
} ) ;
86
88
87
- pool . release ( x2 ) ;
88
- pool . release ( x1 ) ;
89
- pool . release ( x3 ) ;
89
+ pool . release ( item2 ) ;
90
+ pool . release ( item1 ) ;
91
+ pool . release ( item3 ) ;
90
92
} ) ( ) ;
Original file line number Diff line number Diff line change @@ -30,8 +30,8 @@ class Pool {
30
30
item = this . items [ this . current ] ;
31
31
free = this . free [ this . current ] ;
32
32
this . current ++ ;
33
+ if ( this . current === this . size ) this . current = 0 ;
33
34
} while ( ! item || ! free ) ;
34
- if ( this . current === this . size ) this . current = 0 ;
35
35
return item ;
36
36
}
37
37
@@ -98,5 +98,5 @@ class Pool {
98
98
pool . release ( x1 ) ;
99
99
setTimeout ( ( ) => {
100
100
pool . release ( x3 ) ;
101
- } , 3000 ) ;
101
+ } , 6000 ) ;
102
102
} ) ( ) ;
You can’t perform that action at this time.
0 commit comments