Skip to content

Commit 406e7d0

Browse files
committed
Add comment.
1 parent 907008a commit 406e7d0

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

SwiftTask/SwiftTask.swift

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,8 @@ public class Task<Progress, Value, Error>: Cancellable, Printable
374374
}
375375

376376
///
377-
/// then (fulfilled & rejected) + closure returning value
377+
/// then (fulfilled & rejected) + closure returning **value**
378+
/// (a.k.a. `map` in functional programming term)
378379
///
379380
/// - e.g. task.then { value, errorInfo -> NextValueType in ... }
380381
///
@@ -392,7 +393,8 @@ public class Task<Progress, Value, Error>: Cancellable, Printable
392393
}
393394

394395
///
395-
/// then (fulfilled & rejected) + closure returning task
396+
/// then (fulfilled & rejected) + closure returning **task**
397+
/// (a.k.a. `flatMap` in functional programming term)
396398
///
397399
/// - e.g. task.then { value, errorInfo -> NextTaskType in ... }
398400
///
@@ -402,6 +404,12 @@ public class Task<Progress, Value, Error>: Cancellable, Printable
402404
return self.then(&dummyCanceller, thenClosure)
403405
}
404406

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+
//
405413
public func then<Progress2, Value2, C: Canceller>(inout canceller: C?, _ thenClosure: (Value?, ErrorInfo?) -> Task<Progress2, Value2, Error>) -> Task<Progress2, Value2, Error>
406414
{
407415
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
440448
}
441449

442450
///
443-
/// success (fulfilled) + closure returning value
451+
/// success (fulfilled) + closure returning **value**
444452
///
445453
/// - e.g. task.success { value -> NextValueType in ... }
446454
///
@@ -458,7 +466,7 @@ public class Task<Progress, Value, Error>: Cancellable, Printable
458466
}
459467

460468
///
461-
/// success (fulfilled) + closure returning task
469+
/// success (fulfilled) + closure returning **task**
462470
///
463471
/// - e.g. task.success { value -> NextTaskType in ... }
464472
///
@@ -489,7 +497,7 @@ public class Task<Progress, Value, Error>: Cancellable, Printable
489497
}
490498

491499
///
492-
/// failure (rejected) + closure returning value
500+
/// failure (rejected or cancelled) + closure returning **value**
493501
///
494502
/// - e.g. task.failure { errorInfo -> NextValueType in ... }
495503
/// - e.g. task.failure { error, isCancelled -> NextValueType in ... }
@@ -508,7 +516,7 @@ public class Task<Progress, Value, Error>: Cancellable, Printable
508516
}
509517

510518
///
511-
/// failure (rejected) + closure returning task
519+
/// failure (rejected or cancelled) + closure returning **task**
512520
///
513521
/// - e.g. task.failure { errorInfo -> NextTaskType in ... }
514522
/// - e.g. task.failure { error, isCancelled -> NextTaskType in ... }

0 commit comments

Comments
 (0)