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

the documentation for AsyncStream<T>.Continuation has a strange warning that reads:

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

aren’t all continuations inherently escaping?

I'm also confused by this. In an earlier thread from June 2021, @John_McCall says this about a CheckedContinuation:

Escaping the continuation is the expected use pattern.

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.

2 Likes

Thanks John.

I agree.

Terms of Service

Privacy Policy

Cookie Policy