@@ -470,13 +470,13 @@ public class Task<Progress, Value, Error>: Cancellable, Printable
470
470
///
471
471
/// - e.g. task.success { value -> NextTaskType in ... }
472
472
///
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 >
474
474
{
475
475
var dummyCanceller : Canceller ? = nil
476
476
return self . success ( & dummyCanceller, successClosure)
477
477
}
478
478
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 >
480
480
{
481
481
return Task < Progress2 , Value2 , Error > { [ unowned self] newMachine, progress, fulfill, _reject, configure in
482
482
@@ -581,8 +581,8 @@ public class Task<Progress, Value, Error>: Cancellable, Printable
581
581
582
582
// MARK: - Helper
583
583
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 > ,
586
586
newMachine: _StateMachine < Progress2 , Value2 , Error > ,
587
587
progress: Task < Progress2 , Value2 , Error > . ProgressHandler ,
588
588
fulfill: Task < Progress2 , Value2 , Error > . FulfillHandler ,
@@ -595,20 +595,26 @@ internal func _bindInnerTask<Progress2, Value2, Error>(
595
595
fulfill ( innerTask. value!)
596
596
return
597
597
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) )
599
602
return
600
603
default :
601
604
break
602
605
}
603
606
604
607
innerTask. progress { _, progressValue in
605
608
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
607
610
if let value = value {
608
611
fulfill ( value)
609
612
}
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) )
612
618
}
613
619
}
614
620
0 commit comments