Skip to content

Commit 0deb770

Browse files
authored
Merge pull request swiftlang#87082 from jamieQ/astream-cancel-docs
[NFC][Concurrency]: add note about deadlock risk for AsyncStream.onTermination
2 parents f90a4b1 + 2a017d1 commit 0deb770

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

stdlib/public/Concurrency/AsyncStream.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,11 @@ public struct AsyncStream<Element> {
218218
/// needed cleanup in the cancellation handler. After reaching a terminal
219219
/// state as a result of cancellation, the `AsyncStream` sets the callback
220220
/// to `nil`.
221+
///
222+
/// - Note: Because the system might call the `onTermination` callback as
223+
/// part of task cancellation, it's subject to the same considerations for
224+
/// avoiding deadlock as outlined in the documentation for
225+
/// ``withTaskCancellationHandler(operation:onCancel:)``.
221226
public var onTermination: (@Sendable (Termination) -> Void)? {
222227
get {
223228
return storage.getOnTermination()
@@ -329,7 +334,10 @@ public struct AsyncStream<Element> {
329334
/// print(random)
330335
/// }
331336
///
332-
///
337+
/// - Note: Because the system might call the `onCancel` callback as
338+
/// part of task cancellation, it's subject to the same considerations for
339+
/// avoiding deadlock as outlined in the documentation for
340+
/// ``withTaskCancellationHandler(operation:onCancel:)``.
333341
@_silgen_name("$sScS9unfolding8onCancelScSyxGxSgyYac_yyYbcSgtcfC")
334342
@preconcurrency // Original API had `@Sendable` only on `onCancel`
335343
public init(

stdlib/public/Concurrency/AsyncThrowingStream.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,11 @@ public struct AsyncThrowingStream<Element, Failure: Error> {
242242
/// iterator. This means that you can perform needed cleanup in the
243243
/// cancellation handler. After reaching a terminal state, the
244244
/// `AsyncThrowingStream` disposes of the callback.
245+
///
246+
/// - Note: Because the system might call the `onTermination` callback as
247+
/// part of task cancellation, it's subject to the same considerations for
248+
/// avoiding deadlock as outlined in the documentation for
249+
/// ``withTaskCancellationHandler(operation:onCancel:)``.
245250
public var onTermination: (@Sendable (Termination) -> Void)? {
246251
get {
247252
return storage.getOnTermination()

0 commit comments

Comments
 (0)