Skip to content

Commit bde105c

Browse files
committed
channel: update documentation for cancellation
1 parent bdd7bc7 commit bde105c

File tree

3 files changed

+3
-1
lines changed

3 files changed

+3
-1
lines changed

Diff for: Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Channel.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public final class AsyncThrowingChannel<Element: Sendable, Failure: Error>: Asyn
5151
}
5252
```
5353

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.
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. The calls to `send(:)` and `next()` will immediately resume when their supporting task is cancelled, other operations from other tasks will remain active.
5555

5656
```swift
5757
let channel = AsyncChannel<String>()

Diff for: Sources/AsyncAlgorithms/AsyncChannel.swift

+1
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ public final class AsyncChannel<Element: Sendable>: AsyncSequence, Sendable {
235235
/// Send an element to an awaiting iteration. This function will resume when the next call to `next()` is made
236236
/// or when a call to `finish()` is made from another Task.
237237
/// If the channel is already finished then this returns immediately
238+
/// If the task is cancelled, this function will resume. Other sending operations from other tasks will remain active.
238239
public func send(_ element: Element) async {
239240
let generation = establish()
240241
let sendTokenStatus = ManagedCriticalState<ChannelTokenStatus>(.new)

Diff for: Sources/AsyncAlgorithms/AsyncThrowingChannel.swift

+1
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ public final class AsyncThrowingChannel<Element: Sendable, Failure: Error>: Asyn
297297
/// Send an element to an awaiting iteration. This function will resume when the next call to `next()` is made
298298
/// or when a call to `finish()`/`fail(_:)` is made from another Task.
299299
/// If the channel is already finished then this returns immediately
300+
/// If the task is cancelled, this function will resume. Other sending operations from other tasks will remain active.
300301
public func send(_ element: Element) async {
301302
let generation = establish()
302303
let sendTokenStatus = ManagedCriticalState<ChannelTokenStatus>(.new)

0 commit comments

Comments
 (0)