Instance Propertyswift 6.0.3_Concurrency

onTermination

A callback to invoke when canceling iteration of an asynchronous stream.

iOS
13.0+
macOS
10.15+
tvOS
13.0+
watchOS
6.0+
var onTermination: ((AsyncThrowingStream<Element, Failure>.Continuation.Termination) -> Void)? { get nonmutating set }

If an onTermination callback is set, using task cancellation to terminate iteration of an AsyncThrowingStream results in a call to this callback.

Canceling an active iteration invokes the onTermination callback first, and then resumes by yielding nil or throwing an error from the iterator. This means that you can perform needed cleanup in the cancellation handler. After reaching a terminal state, the AsyncThrowingStream disposes of the callback.