Instance Property インスタンスプロパティ

onTermination

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

Declaration 宣言

var onTermination: (@Sendable (AsyncStream<Element>.Continuation.Termination) -> Void)? { get nonmutating set }

Discussion 解説

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

Canceling an active iteration invokes the onTermination callback first, then resumes by yielding nil. This means that you can perform needed cleanup in the cancellation handler. After reaching a terminal state as a result of cancellation, the AsyncStream sets the callback to nil.

See Also 参照

Handling Termination