@@ -13,7 +13,7 @@ export type JobFunc<T> = (job: JobHandle) => Promise<Outcome<T>>
13
13
* A handle for the current job used in [JobFunc]. This interface is equivalent to [Job]'s interface with the exception
14
14
* of [run] and [runWithTimeout] to prevent recursive running of the [Job] inside its [JobFunc].
15
15
*/
16
- interface JobHandle {
16
+ export interface JobHandle {
17
17
isActive : boolean
18
18
isCompleted : boolean
19
19
isCancelled : boolean
@@ -24,7 +24,10 @@ interface JobHandle {
24
24
pause < R > ( func : Promise < R > ) : Promise < R >
25
25
delay ( milliseconds : number ) : Promise < void >
26
26
cancel ( reason ?: JobCancellationException ) : void
27
- cancelChildren ( reason ?: JobCancellationException ) : void
27
+ cancelChildren (
28
+ reason ?: JobCancellationException ,
29
+ skipChildren ?: JobHandle [ ]
30
+ ) : void
28
31
}
29
32
30
33
/**
@@ -281,14 +284,20 @@ export class Job<T> implements JobHandle {
281
284
/**
282
285
* Cancels all children jobs without cancelling the current job.
283
286
*/
284
- cancelChildren ( reason ?: JobCancellationException ) {
287
+ cancelChildren (
288
+ reason ?: JobCancellationException ,
289
+ skipChildren : JobHandle [ ] = [ ]
290
+ ) {
285
291
const childrenCopy = [ ...this . _children ]
286
- childrenCopy . forEach ( ( job ) =>
287
- job . cancel (
288
- reason ??
289
- new JobCancellationException ( JobCancellationReason . JobCancelled )
290
- )
291
- )
292
+ const skipSet = new Set ( skipChildren )
293
+ childrenCopy . forEach ( ( job ) => {
294
+ if ( ! skipSet . has ( job ) ) {
295
+ job . cancel (
296
+ reason ??
297
+ new JobCancellationException ( JobCancellationReason . JobCancelled )
298
+ )
299
+ }
300
+ } )
292
301
this . _children = [ ]
293
302
}
294
303
0 commit comments