@@ -398,7 +398,7 @@ public class Task<Progress, Value, Error>: Cancellable, Printable
398
398
///
399
399
/// - e.g. task.then { value, errorInfo -> NextTaskType in ... }
400
400
///
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 >
402
402
{
403
403
var dummyCanceller : Canceller ? = nil
404
404
return self . then ( & dummyCanceller, thenClosure)
@@ -410,9 +410,9 @@ public class Task<Progress, Value, Error>: Cancellable, Printable
410
410
// - `let canceller = Canceller(); task1.then(&canceller) {...}; canceller.cancel();`
411
411
// - `let task2 = task1.then {...}; task2.cancel();`
412
412
//
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 >
414
414
{
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
416
416
417
417
//
418
418
// NOTE:
@@ -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
@@ -521,15 +521,15 @@ public class Task<Progress, Value, Error>: Cancellable, Printable
521
521
/// - e.g. task.failure { errorInfo -> NextTaskType in ... }
522
522
/// - e.g. task.failure { error, isCancelled -> NextTaskType in ... }
523
523
///
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 >
525
525
{
526
526
var dummyCanceller : Canceller ? = nil
527
527
return self . failure ( & dummyCanceller, failureClosure)
528
528
}
529
529
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 >
531
531
{
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
533
533
534
534
let selfMachine = self . _machine
535
535
@@ -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