File tree 1 file changed +13
-7
lines changed
1 file changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -39,25 +39,31 @@ export class Task<E, S> implements PromiseLike<S> {
39
39
public isCanceled = false ;
40
40
constructor ( private computation : Fork < E , S > ) { }
41
41
42
- fork ( reject : Reject < E > , resolve : Resolve < S > ) {
43
- if ( this . isCanceled ) {
44
- return this ;
42
+ fork ( reject : Reject < E > , resolve : Resolve < S > ) : { cancel : ( ) => void } {
43
+ let localCancel = this . isCanceled ;
44
+
45
+ const result = {
46
+ cancel : ( ) => ( localCancel = true )
47
+ } ;
48
+
49
+ if ( localCancel ) {
50
+ return result ;
45
51
}
46
52
47
53
this . computation (
48
54
err => {
49
- if ( ! this . isCanceled ) {
55
+ if ( ! localCancel ) {
50
56
reject ( err ) ;
51
57
}
52
58
} ,
53
59
value => {
54
- if ( ! this . isCanceled ) {
60
+ if ( ! localCancel ) {
55
61
resolve ( value ) ;
56
62
}
57
63
}
58
64
) ;
59
65
60
- return this ;
66
+ return result ;
61
67
}
62
68
63
69
cancel ( ) {
@@ -313,7 +319,7 @@ export function fork<E, S>(
313
319
reject : Reject < E > ,
314
320
resolve : Resolve < S > ,
315
321
task : Task < E , S >
316
- ) : Task < E , S > {
322
+ ) : { cancel : ( ) => void } {
317
323
return task . fork ( reject , resolve ) ;
318
324
}
319
325
You can’t perform that action at this time.
0 commit comments