This repository was archived by the owner on Dec 15, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +28
-11
lines changed Expand file tree Collapse file tree 2 files changed +28
-11
lines changed Original file line number Diff line number Diff line change @@ -8,8 +8,13 @@ class Task {
8
8
} ) ;
9
9
}
10
10
11
- execute ( ) {
12
- return this . fn . call ( undefined ) . then ( this . resolve , this . reject ) ;
11
+ async execute ( ) {
12
+ try {
13
+ const value = await this . fn . call ( undefined ) ;
14
+ this . resolve ( value ) ;
15
+ } catch ( err ) {
16
+ this . reject ( err ) ;
17
+ }
13
18
}
14
19
15
20
runsInParallel ( ) {
@@ -55,14 +60,9 @@ export default class AsyncQueue {
55
60
this . nonParallelizableOperation = true ;
56
61
}
57
62
58
- try {
59
- await task . execute ( ) ;
60
- } catch ( err ) {
61
- // nothing
62
- } finally {
63
- this . threadsInUse -- ;
64
- this . nonParallelizableOperation = false ;
65
- this . processQueue ( ) ;
66
- }
63
+ await task . execute ( ) ;
64
+ this . threadsInUse -- ;
65
+ this . nonParallelizableOperation = false ;
66
+ this . processQueue ( ) ;
67
67
}
68
68
}
Original file line number Diff line number Diff line change @@ -128,4 +128,21 @@ describe('AsyncQueue', function() {
128
128
await assert . async . isTrue ( tasks [ 4 ] . started ) ; // both can start since they are parallelizable
129
129
assert . isTrue ( tasks [ 5 ] . started ) ;
130
130
} ) ;
131
+
132
+ it ( 'continues to work when tasks throw synchronous errors' , async function ( ) {
133
+ const queue = new AsyncQueue ( { parallelism : 1 } ) ;
134
+
135
+ const p1 = queue . push ( ( ) => {
136
+ throw new Error ( 'error thrown from task 1' ) ;
137
+ } ) ;
138
+ const p2 = queue . push ( ( ) => {
139
+ return new Promise ( res => res ( 2 ) ) ;
140
+ } ) ;
141
+
142
+ try {
143
+ await p1 ;
144
+ throw new Error ( 'expected p1 to be rejectd' ) ;
145
+ } catch ( err ) { }
146
+ assert . equal ( await p2 , 2 ) ;
147
+ } ) ;
131
148
} ) ;
You can’t perform that action at this time.
0 commit comments