10.6 · Continuations and bridging GCD, Combine and callback APIs

Most real code is mixed: callbacks, delegates, Combine and GCD on one side, async/await on the other. Continuations and async streams are the adapters.

Mental model. A callback API is one or many future results. One result becomes a continuation, many become an AsyncStream. The only rule: resume exactly once.

Adapters

Continuations, and streams for repeated events.

  1. How do continuations bridge callback APIs, and what is the difference between checked and unsafe? 10.6.1 · L3
    A continuation lets an async function wait for a callback: await withCheckedContinuation { c in legacy { c.resume(returning: $0) } } (or…
  2. How do you bridge repeated events, GCD and Combine into async code with AsyncStream? 10.6.2 · L3
    When an API delivers many values over time (delegate callbacks, notifications, location updates, a Combine publisher) wrap it in an AsyncStream (non-throwing)…

More in Concurrency