Concurrency
Dive deep into Swift’s latest concurrency changes, covering async-await, actors, and more.
AsyncSequence explained with Code Examples
AsyncSequence is part of the concurrency framework and the SE-298 proposal. Its name implies it's a type providing asynchronous, sequential, and iterated access to its elements. In other words: it's an asynchronous variant of the regular sequence we're familiar with in Swift. Like you won't often create your custom Sequence ...
AsyncThrowingStream and AsyncStream explained with code examples
AsyncThrowingStream and AsyncStream are part of the concurrency framework introduced in Swift 5.5 due to SE-314. Async streams allow you to replace existing code that is based on closures or Combine publishers. Before diving into details around throwing streams, I recommend reading my article covering async-await if you didn't do ...
Tasks in Swift explained with code examples
Tasks in Swift are part of the concurrency framework introduced at WWDC 2021. A task allows us to create a concurrent environment from a non-concurrent method, calling methods using async/await. When working with tasks for the first time, you might recognize familiarities between dispatch queues and tasks. Both allow dispatching ...
Nonisolated and isolated keywords: Understanding Actor isolation
SE-313 introduced the nonisolated and isolated keywords as part of adding actor isolation control. Actors are a new way of providing synchronization for shared mutable states with the new concurrency framework. If you're new to actors in Swift, I encourage you to read my article Actors in Swift: how to ...
Async let explained: call async functions in parallel
Async let is part of Swift's concurrency framework and allows instantiating a constant asynchronously. The concurrency framework introduced the concept of async-await, which results in structured concurrency and more readable code for asynchronous methods. If you're new to async-await, it's recommended first to read my article Async await in Swift ...
Actors in Swift: how to use and prevent data races
Swift Actors are new in Swift 5.5 and are part of the big concurrency changes at WWDC 2021. Before actors, data races were a common exception to run into. So before we dive into Actors with isolated and nonisolated access, it's good to understand what Data Races are and to ...