@@ -398,7 +398,7 @@ public class Task<Progress, Value, Error>: Cancellable, Printable
398398 ///
399399 /// - e.g. task.then { value, errorInfo -> NextTaskType in ... }
400400 ///
401- public func then< Progress2, Value2> ( thenClosure: ( Value ? , ErrorInfo ? ) -> Task < Progress2 , Value2 , Error > ) -> Task < Progress2 , Value2 , Error >
401+ public func then< Progress2, Value2, Error2 > ( thenClosure: ( Value ? , ErrorInfo ? ) -> Task < Progress2 , Value2 , Error2 > ) -> Task < Progress2 , Value2 , Error2 >
402402 {
403403 var dummyCanceller : Canceller ? = nil
404404 return self . then ( & dummyCanceller, thenClosure)
@@ -410,9 +410,9 @@ public class Task<Progress, Value, Error>: Cancellable, Printable
410410 // - `let canceller = Canceller(); task1.then(&canceller) {...}; canceller.cancel();`
411411 // - `let task2 = task1.then {...}; task2.cancel();`
412412 //
413- public func then< Progress2, Value2, C: Canceller > ( inout canceller: C ? , _ thenClosure: ( Value ? , ErrorInfo ? ) -> Task < Progress2 , Value2 , Error > ) -> Task < Progress2 , Value2 , Error >
413+ public func then< Progress2, Value2, Error2 , C: Canceller > ( inout canceller: C ? , _ thenClosure: ( Value ? , ErrorInfo ? ) -> Task < Progress2 , Value2 , Error2 > ) -> Task < Progress2 , Value2 , Error2 >
414414 {
415- return Task < Progress2 , Value2 , Error > { [ unowned self, weak canceller] newMachine, progress, fulfill, _reject, configure in
415+ return Task < Progress2 , Value2 , Error2 > { [ unowned self, weak canceller] newMachine, progress, fulfill, _reject, configure in
416416
417417 //
418418 // NOTE:
@@ -470,13 +470,13 @@ public class Task<Progress, Value, Error>: Cancellable, Printable
470470 ///
471471 /// - e.g. task.success { value -> NextTaskType in ... }
472472 ///
473- public func success< Progress2, Value2> ( successClosure: Value -> Task < Progress2 , Value2 , Error > ) -> Task < Progress2 , Value2 , Error >
473+ public func success< Progress2, Value2, Error2 > ( successClosure: Value -> Task < Progress2 , Value2 , Error2 > ) -> Task < Progress2 , Value2 , Error >
474474 {
475475 var dummyCanceller : Canceller ? = nil
476476 return self . success ( & dummyCanceller, successClosure)
477477 }
478478
479- public func success< Progress2, Value2, C: Canceller > ( inout canceller: C ? , _ successClosure: Value -> Task < Progress2 , Value2 , Error > ) -> Task < Progress2 , Value2 , Error >
479+ public func success< Progress2, Value2, Error2 , C: Canceller > ( inout canceller: C ? , _ successClosure: Value -> Task < Progress2 , Value2 , Error2 > ) -> Task < Progress2 , Value2 , Error >
480480 {
481481 return Task < Progress2 , Value2 , Error > { [ unowned self] newMachine, progress, fulfill, _reject, configure in
482482
@@ -521,15 +521,15 @@ public class Task<Progress, Value, Error>: Cancellable, Printable
521521 /// - e.g. task.failure { errorInfo -> NextTaskType in ... }
522522 /// - e.g. task.failure { error, isCancelled -> NextTaskType in ... }
523523 ///
524- public func failure< Progress2> ( failureClosure: ErrorInfo -> Task < Progress2 , Value , Error > ) -> Task < Progress2 , Value , Error >
524+ public func failure< Progress2, Error2 > ( failureClosure: ErrorInfo -> Task < Progress2 , Value , Error2 > ) -> Task < Progress2 , Value , Error2 >
525525 {
526526 var dummyCanceller : Canceller ? = nil
527527 return self . failure ( & dummyCanceller, failureClosure)
528528 }
529529
530- public func failure< Progress2, C: Canceller > ( inout canceller: C ? , _ failureClosure: ErrorInfo -> Task < Progress2 , Value , Error > ) -> Task < Progress2 , Value , Error >
530+ public func failure< Progress2, Error2 , C: Canceller > ( inout canceller: C ? , _ failureClosure: ErrorInfo -> Task < Progress2 , Value , Error2 > ) -> Task < Progress2 , Value , Error2 >
531531 {
532- return Task < Progress2 , Value , Error > { [ unowned self] newMachine, progress, fulfill, _reject, configure in
532+ return Task < Progress2 , Value , Error2 > { [ unowned self] newMachine, progress, fulfill, _reject, configure in
533533
534534 let selfMachine = self . _machine
535535
@@ -581,8 +581,8 @@ public class Task<Progress, Value, Error>: Cancellable, Printable
581581
582582// MARK: - Helper
583583
584- internal func _bindInnerTask< Progress2, Value2, Error> (
585- innerTask: Task < Progress2 , Value2 , Error > ,
584+ internal func _bindInnerTask< Progress2, Value2, Error, Error2 > (
585+ innerTask: Task < Progress2 , Value2 , Error2 > ,
586586 newMachine: _StateMachine < Progress2 , Value2 , Error > ,
587587 progress: Task < Progress2 , Value2 , Error > . ProgressHandler ,
588588 fulfill: Task < Progress2 , Value2 , Error > . FulfillHandler ,
@@ -595,20 +595,26 @@ internal func _bindInnerTask<Progress2, Value2, Error>(
595595 fulfill ( innerTask. value!)
596596 return
597597 case . Rejected, . Cancelled:
598- _reject ( innerTask. errorInfo!)
598+ let ( error2, isCancelled) = innerTask. errorInfo!
599+
600+ // NOTE: innerTask's `error2` will be treated as `nil` if not same type as outerTask's `Error` type
601+ _reject ( ( error2 as? Error , isCancelled) )
599602 return
600603 default :
601604 break
602605 }
603606
604607 innerTask. progress { _, progressValue in
605608 progress ( progressValue)
606- } . then { ( value: Value2 ? , errorInfo : Task < Progress2 , Value2 , Error > . ErrorInfo ? ) -> Void in
609+ } . then { ( value: Value2 ? , errorInfo2 : Task < Progress2 , Value2 , Error2 > . ErrorInfo ? ) -> Void in
607610 if let value = value {
608611 fulfill ( value)
609612 }
610- else if let errorInfo = errorInfo {
611- _reject ( errorInfo)
613+ else if let errorInfo2 = errorInfo2 {
614+ let ( error2, isCancelled) = errorInfo2
615+
616+ // NOTE: innerTask's `error2` will be treated as `nil` if not same type as outerTask's `Error` type
617+ _reject ( ( error2 as? Error , isCancelled) )
612618 }
613619 }
614620
0 commit comments