@@ -359,15 +359,33 @@ public class Task<Progress, Value, Error>: _Task<Error>
359
359
360
360
if initClosure == nil { return self }
361
361
362
- var nextTask : Task = self
362
+ let newTask = Task { [ weak self] machine, progress, fulfill, _reject, configure in
363
+
364
+ var nextTask : Task = self !
363
365
364
- for i in 1 ... maxTryCount- 1 {
365
- nextTask = nextTask. failure { _ -> Task in
366
- return Task ( weakified: weakified, _initClosure: initClosure!) // create a clone-task when rejected
366
+ for i in 1 ... maxTryCount- 1 {
367
+ nextTask = nextTask. progress { _, progressValue in
368
+ progress ( progressValue)
369
+ } . failure { _ -> Task in
370
+ return Task ( weakified: weakified, _initClosure: initClosure!) // create a clone-task when rejected
371
+ }
372
+ }
373
+
374
+ nextTask. progress { _, progressValue in
375
+ progress ( progressValue)
376
+ } . success { value -> Void in
377
+ fulfill ( value)
378
+ } . failure { errorInfo -> Void in
379
+ _reject ( errorInfo)
367
380
}
381
+
382
+ configure. pause = { nextTask. pause ( ) ; return }
383
+ configure. resume = { nextTask. resume ( ) ; return }
384
+ configure. cancel = { nextTask. cancel ( ) ; return }
385
+
368
386
}
369
387
370
- return nextTask
388
+ return newTask
371
389
}
372
390
373
391
///
@@ -455,11 +473,12 @@ public class Task<Progress, Value, Error>: _Task<Error>
455
473
case . Rejected:
456
474
bind ( nil , self_. errorInfo!)
457
475
default :
458
- self_. machine. addEventHandler ( . Progress) { context in
459
- if let ( _, progressValue) = context. userInfo as? Task < Progress2 , Value2 , Error > . ProgressTuple {
460
- progress ( progressValue)
461
- }
462
- }
476
+ // comment-out: only innerTask's progress should be sent to newTask
477
+ // self_.machine.addEventHandler(.Progress) { context in
478
+ // if let (_, progressValue) = context.userInfo as? Task<Progress2, Value2, Error>.ProgressTuple {
479
+ // progress(progressValue)
480
+ // }
481
+ // }
463
482
self_. machine. addEventHandler ( . Fulfill) { context in
464
483
if let value = context. userInfo as? Value {
465
484
bind ( value, nil )
@@ -535,11 +554,12 @@ public class Task<Progress, Value, Error>: _Task<Error>
535
554
case . Rejected:
536
555
_reject ( self_. errorInfo!)
537
556
default :
538
- self_. machine. addEventHandler ( . Progress) { context in
539
- if let ( _, progressValue) = context. userInfo as? Task < Progress2 , Value2 , Error > . ProgressTuple {
540
- progress ( progressValue)
541
- }
542
- }
557
+ // comment-out: only innerTask's progress should be sent to newTask
558
+ // self_.machine.addEventHandler(.Progress) { context in
559
+ // if let (_, progressValue) = context.userInfo as? Task<Progress2, Value2, Error>.ProgressTuple {
560
+ // progress(progressValue)
561
+ // }
562
+ // }
543
563
self_. machine. addEventHandler ( . Fulfill) { context in
544
564
if let value = context. userInfo as? Value {
545
565
bind ( value)
@@ -618,11 +638,12 @@ public class Task<Progress, Value, Error>: _Task<Error>
618
638
let errorInfo = self_. errorInfo!
619
639
bind ( errorInfo)
620
640
default :
621
- self_. machine. addEventHandler ( . Progress) { context in
622
- if let ( _, progressValue) = context. userInfo as? Task . ProgressTuple {
623
- progress ( progressValue)
624
- }
625
- }
641
+ // comment-out: only innerTask's progress should be sent to newTask
642
+ // self_.machine.addEventHandler(.Progress) { context in
643
+ // if let (_, progressValue) = context.userInfo as? Task.ProgressTuple {
644
+ // progress(progressValue)
645
+ // }
646
+ // }
626
647
self_. machine. addEventHandler ( . Fulfill) { context in
627
648
if let value = context. userInfo as? Value {
628
649
fulfill ( value)
0 commit comments