@@ -32,10 +32,7 @@ class Queue {
32
32
add ( task ) {
33
33
if ( ! this . paused ) {
34
34
const hasChannel = this . count < this . concurrency ;
35
- if ( hasChannel ) {
36
- this . next ( task ) ;
37
- return ;
38
- }
35
+ if ( hasChannel ) return void this . next ( task ) ;
39
36
}
40
37
this . waiting . push ( { task, start : Date . now ( ) } ) ;
41
38
}
@@ -45,17 +42,17 @@ class Queue {
45
42
let timer = null ;
46
43
let finished = false ;
47
44
const { processTimeout, onProcess } = this ;
48
- const finish = ( err , res ) => {
45
+ const finish = ( error , res ) => {
49
46
if ( finished ) return ;
50
47
finished = true ;
51
48
if ( timer ) clearTimeout ( timer ) ;
52
49
this . count -- ;
53
- this . finish ( err , res ) ;
50
+ this . finish ( error , res ) ;
54
51
if ( ! this . paused && this . waiting . length > 0 ) this . takeNext ( ) ;
55
52
} ;
56
53
if ( processTimeout !== Infinity ) {
57
- const err = new Error ( 'Process timed out' ) ;
58
- timer = setTimeout ( finish , processTimeout , err , task ) ;
54
+ const error = new Error ( 'Process timed out' ) ;
55
+ timer = setTimeout ( finish , processTimeout , error , task ) ;
59
56
}
60
57
onProcess ( task , finish ) ;
61
58
}
@@ -66,8 +63,8 @@ class Queue {
66
63
if ( waitTimeout !== Infinity ) {
67
64
const delay = Date . now ( ) - start ;
68
65
if ( delay > waitTimeout ) {
69
- const err = new Error ( 'Waiting timed out' ) ;
70
- this . finish ( err , task ) ;
66
+ const error = new Error ( 'Waiting timed out' ) ;
67
+ this . finish ( error , task ) ;
71
68
if ( waiting . length > 0 ) {
72
69
setTimeout ( ( ) => {
73
70
if ( ! this . paused && waiting . length > 0 ) this . takeNext ( ) ;
@@ -78,17 +75,16 @@ class Queue {
78
75
}
79
76
const hasChannel = this . count < this . concurrency ;
80
77
if ( hasChannel ) this . next ( task ) ;
81
- return ;
82
78
}
83
79
84
- finish ( err , res ) {
80
+ finish ( error , res ) {
85
81
const { onFailure, onSuccess, onDone, onDrain } = this ;
86
- if ( err ) {
87
- if ( onFailure ) onFailure ( err , res ) ;
82
+ if ( error ) {
83
+ if ( onFailure ) onFailure ( error , res ) ;
88
84
} else if ( onSuccess ) {
89
85
onSuccess ( res ) ;
90
86
}
91
- if ( onDone ) onDone ( err , res ) ;
87
+ if ( onDone ) onDone ( error , res ) ;
92
88
if ( this . count === 0 && onDrain ) onDrain ( ) ;
93
89
}
94
90
@@ -144,12 +140,8 @@ const queue = Queue.channels(3)
144
140
. wait ( 4000 )
145
141
. timeout ( 5000 )
146
142
. process ( job )
147
- . success ( ( task ) => {
148
- console . log ( `Success: ${ task . name } ` ) ;
149
- } )
150
- . failure ( ( error , task ) => {
151
- console . log ( `Failure: ${ error } ${ task . name } ` ) ;
152
- } )
143
+ . success ( ( task ) => void console . log ( `Success: ${ task . name } ` ) )
144
+ . failure ( ( error , task ) => void console . log ( `Failure: ${ error } ${ task . name } ` ) )
153
145
. pause ( ) ;
154
146
155
147
for ( let i = 0 ; i < 10 ; i ++ ) {
0 commit comments