File tree 1 file changed +11
-13
lines changed
1 file changed +11
-13
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,6 @@ class Queue {
5
5
this . concurrency = concurrency ;
6
6
this . count = 0 ;
7
7
this . waiting = [ ] ;
8
- this . promises = [ ] ;
9
8
this . onProcess = null ;
10
9
this . onDone = null ;
11
10
this . onSuccess = null ;
@@ -31,25 +30,24 @@ class Queue {
31
30
const task = this . waiting . shift ( ) ;
32
31
this . onProcess ( task )
33
32
. then (
34
- ( res ) => {
35
- if ( this . onSuccess ) this . onSuccess ( res ) ;
36
- if ( this . onDone ) this . onDone ( null , res ) ;
37
- } ,
38
- ( err ) => {
39
- if ( this . onFailure ) this . onFailure ( err ) ;
40
- if ( this . onDone ) this . onDone ( err ) ;
41
- }
33
+ ( res ) => void this . finish ( null , res ) ,
34
+ ( err ) => void this . finish ( err )
42
35
)
43
36
. finally ( ( ) => {
44
37
this . count -- ;
45
- if ( this . count === 0 && this . waiting . length === 0 ) {
46
- if ( this . onDrain ) this . onDrain ( ) ;
47
- }
48
- this . next ( ) ;
38
+ if ( this . waiting . length > 0 ) this . next ( ) ;
49
39
} ) ;
50
40
}
51
41
}
52
42
43
+ finish ( err , res ) {
44
+ const { onFailure, onSuccess, onDone, onDrain } = this ;
45
+ if ( err && onFailure ) onFailure ( err , res ) ;
46
+ else if ( onSuccess ) onSuccess ( res ) ;
47
+ if ( onDone ) onDone ( err , res ) ;
48
+ if ( this . count === 0 && this . waiting . length === 0 && onDrain ) onDrain ( ) ;
49
+ }
50
+
53
51
process ( listener ) {
54
52
this . onProcess = listener ;
55
53
return this ;
You can’t perform that action at this time.
0 commit comments