@@ -359,15 +359,33 @@ public class Task<Progress, Value, Error>: _Task<Error>
359359
360360 if initClosure == nil { return self }
361361
362- var nextTask : Task = self
362+ let newTask = Task { [ weak self] machine, progress, fulfill, _reject, configure in
363+
364+ var nextTask : Task = self !
363365
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)
367380 }
381+
382+ configure. pause = { nextTask. pause ( ) ; return }
383+ configure. resume = { nextTask. resume ( ) ; return }
384+ configure. cancel = { nextTask. cancel ( ) ; return }
385+
368386 }
369387
370- return nextTask
388+ return newTask
371389 }
372390
373391 ///
@@ -455,11 +473,12 @@ public class Task<Progress, Value, Error>: _Task<Error>
455473 case . Rejected:
456474 bind ( nil , self_. errorInfo!)
457475 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+ // }
463482 self_. machine. addEventHandler ( . Fulfill) { context in
464483 if let value = context. userInfo as? Value {
465484 bind ( value, nil )
@@ -535,11 +554,12 @@ public class Task<Progress, Value, Error>: _Task<Error>
535554 case . Rejected:
536555 _reject ( self_. errorInfo!)
537556 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+ // }
543563 self_. machine. addEventHandler ( . Fulfill) { context in
544564 if let value = context. userInfo as? Value {
545565 bind ( value)
@@ -618,11 +638,12 @@ public class Task<Progress, Value, Error>: _Task<Error>
618638 let errorInfo = self_. errorInfo!
619639 bind ( errorInfo)
620640 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+ // }
626647 self_. machine. addEventHandler ( . Fulfill) { context in
627648 if let value = context. userInfo as? Value {
628649 fulfill ( value)
0 commit comments