You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[AsyncThrowingChannel] make the fail terminal event non async (#164)
* asyncThrowingChannel: make fail set a terminal state
* asyncChannel: align naming on asyncThrowingChannel
* asyncChannel: remove a test base on Task.sleep
* guides: update Channel with non async fail(_:)
publicfuncfail(_error: Error) where Failure ==Error
48
48
publicfuncfinish()
49
49
50
50
publicfuncmakeAsyncIterator() ->Iterator
51
51
}
52
52
```
53
53
54
-
Channels are intended to be used as communication types between tasks. Particularly when one task produces values and another task consumes said values. On the one hand, the back pressure applied by `send(_:)`and `fail(_:)`via the suspension/resume ensure that the production of values does not exceed the consumption of values from iteration. Each of these methods suspend after enqueuing the event and are resumed when the next call to `next()` on the `Iterator` is made. On the other hand, the call to `finish()` immediately resumes all the pending operations for every producers and consumers. Thus, every suspended `send(_:)` operations instantly resume, so as every suspended `next()` operations by producing a nil value, indicating the termination of the iterations. Further calls to `send(_:)` will immediately resume.
54
+
Channels are intended to be used as communication types between tasks. Particularly when one task produces values and another task consumes said values. On the one hand, the back pressure applied by `send(_:)` via the suspension/resume ensures that the production of values does not exceed the consumption of values from iteration. This method suspends after enqueuing the event and is resumed when the next call to `next()` on the `Iterator` is made. On the other hand, the call to `finish()`or `fail(_:)`immediately resumes all the pending operations for every producers and consumers. Thus, every suspended `send(_:)` operations instantly resume, so as every suspended `next()` operations by producing a nil value, or by throwing an error, indicating the termination of the iterations. Further calls to `send(_:)` will immediately resume.
Copy file name to clipboardExpand all lines: Sources/AsyncAlgorithms/AsyncThrowingChannel.swift
+79-37Lines changed: 79 additions & 37 deletions
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,13 @@
11
11
12
12
/// An error-throwing channel for sending elements from on task to another with back pressure.
13
13
///
14
-
/// The `AsyncThrowingChannel` class is intended to be used as a communication types between tasks, particularly when one task produces values and another task consumes those values. The back pressure applied by `send(_:)`, `fail(_:)` and `finish()` via suspension/resume ensures that the production of values does not exceed the consumption of values from iteration. Each of these methods suspends after enqueuing the event and is resumed when the next call to `next()` on the `Iterator` is made.
14
+
/// The `AsyncThrowingChannel` class is intended to be used as a communication types between tasks,
15
+
/// particularly when one task produces values and another task consumes those values. The back
16
+
/// pressure applied by `send(_:)` via suspension/resume ensures that the production of values does
17
+
/// not exceed the consumption of values from iteration. This method suspends after enqueuing the event
18
+
/// and is resumed when the next call to `next()` on the `Iterator` is made, or when `finish()`/`fail(_:)` is called
19
+
/// from another Task. As `finish()` and `fail(_:)` induce a terminal state, there is no need for a back pressure management.
20
+
/// Those functions do not suspend and will finish all the pending iterations.
0 commit comments