swift
e52d52c2 - [Concurrency] Call AsyncStream(unfolding:onCancel:)'s onCancel at most once

Commit
3 days ago
[Concurrency] Call AsyncStream(unfolding:onCancel:)'s onCancel at most once withTaskCancellationHandler runs its handler immediately whenever it is entered on an already-cancelled task, so after the consuming task was cancelled every subsequent next() called onCancel again. In particular, a producer that ignores cancellation and returns a value caused onCancel to run twice: once when the task was cancelled and once on the following next(). Clear the stored producer with an atomic take and only call onCancel if this handler is the one that observed it. As a result onCancel is also no longer called if the stream had already finished normally. The init's mangled name and signature are unchanged. Fixes rdar://156074753 Fixes https://github.com/swiftlang/swift/issues/83137
Author
Parents
Loading