“Unlike other continuations in Swift, AsyncStream.Continuation supports escaping.”

I think we might be using slightly different senses of "escaping" in those places.

A task continuation can "escape" the compiler's capacity to statically analyze how it's going to be resumed. In fact, we expect it to, because the only alternative would be to force it to be resumed within the static and synchronous duration of the withContinuation block, which would not be very useful.

Once you've resumed a task continuation, you cannot resume it again, which means its useful lifetime is bounded in time. I can see why someone would think of this as a restriction against a kind of "escape", and I think that's how the AsyncStream documentation means it, because IIUC there isn't an analogous restriction. However, I wouldn't personally call this an "escape" because I think it's better to reserve "escape" for this concept of a statically-enforceable limitation on the use of a value.

5 Likes