@@ -374,7 +374,8 @@ public class Task<Progress, Value, Error>: Cancellable, Printable
374
374
}
375
375
376
376
///
377
- /// then (fulfilled & rejected) + closure returning value
377
+ /// then (fulfilled & rejected) + closure returning **value**
378
+ /// (a.k.a. `map` in functional programming term)
378
379
///
379
380
/// - e.g. task.then { value, errorInfo -> NextValueType in ... }
380
381
///
@@ -392,7 +393,8 @@ public class Task<Progress, Value, Error>: Cancellable, Printable
392
393
}
393
394
394
395
///
395
- /// then (fulfilled & rejected) + closure returning task
396
+ /// then (fulfilled & rejected) + closure returning **task**
397
+ /// (a.k.a. `flatMap` in functional programming term)
396
398
///
397
399
/// - e.g. task.then { value, errorInfo -> NextTaskType in ... }
398
400
///
@@ -402,6 +404,12 @@ public class Task<Progress, Value, Error>: Cancellable, Printable
402
404
return self . then ( & dummyCanceller, thenClosure)
403
405
}
404
406
407
+ //
408
+ // NOTE: then-canceller is a shorthand of `task.cancel(nil)`, i.e. these two are the same:
409
+ //
410
+ // - `let canceller = Canceller(); task1.then(&canceller) {...}; canceller.cancel();`
411
+ // - `let task2 = task1.then {...}; task2.cancel();`
412
+ //
405
413
public func then< Progress2, Value2, C: Canceller > ( inout canceller: C ? , _ thenClosure: ( Value ? , ErrorInfo ? ) -> Task < Progress2 , Value2 , Error > ) -> Task < Progress2 , Value2 , Error >
406
414
{
407
415
return Task < Progress2 , Value2 , Error > { [ unowned self, weak canceller] newMachine, progress, fulfill, _reject, configure in
@@ -440,7 +448,7 @@ public class Task<Progress, Value, Error>: Cancellable, Printable
440
448
}
441
449
442
450
///
443
- /// success (fulfilled) + closure returning value
451
+ /// success (fulfilled) + closure returning ** value**
444
452
///
445
453
/// - e.g. task.success { value -> NextValueType in ... }
446
454
///
@@ -458,7 +466,7 @@ public class Task<Progress, Value, Error>: Cancellable, Printable
458
466
}
459
467
460
468
///
461
- /// success (fulfilled) + closure returning task
469
+ /// success (fulfilled) + closure returning ** task**
462
470
///
463
471
/// - e.g. task.success { value -> NextTaskType in ... }
464
472
///
@@ -489,7 +497,7 @@ public class Task<Progress, Value, Error>: Cancellable, Printable
489
497
}
490
498
491
499
///
492
- /// failure (rejected) + closure returning value
500
+ /// failure (rejected or cancelled ) + closure returning ** value**
493
501
///
494
502
/// - e.g. task.failure { errorInfo -> NextValueType in ... }
495
503
/// - e.g. task.failure { error, isCancelled -> NextValueType in ... }
@@ -508,7 +516,7 @@ public class Task<Progress, Value, Error>: Cancellable, Printable
508
516
}
509
517
510
518
///
511
- /// failure (rejected) + closure returning task
519
+ /// failure (rejected or cancelled ) + closure returning ** task**
512
520
///
513
521
/// - e.g. task.failure { errorInfo -> NextTaskType in ... }
514
522
/// - e.g. task.failure { error, isCancelled -> NextTaskType in ... }
0 commit comments