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.
- How do continuations bridge callback APIs, and what is the difference between checked and unsafe?
A continuation lets an async function wait for a callback: await withCheckedContinuation { c in legacy { c.resume(returning: $0) } } (or… - How do you bridge repeated events, GCD and Combine into async code with AsyncStream?
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
- 10.1 · Queues, QoS, barriers, groups, semaphores and sources
- 10.2 · Operation, OperationQueue, dependencies and cancellation
- 10.3 · async/await, tasks, task groups, cancellation and task locals
- 10.4 · Actors, reentrancy, isolated, nonisolated, global actors and @MainActor
- 10.5 · Region-based isolation, sending, and migrating to Swift 6
- 10.7 · Deadlocks, main-actor hops, Thread Sanitizer and Instruments
- 10.8 · Task groups, async let, cancellation and task locals in practice
- 10.9 · Isolation rules, isolated parameters, global actors, main-actor hops and default isolation
- 10.10 · Sendable rules, locks versus actors, and the escape hatches
- 10.11 · Groups, semaphores, parallel loops, operation dependencies, QoS and timers
- 10.12 · AsyncStream buffering, continuation misuse and notifications as async sequences