Swift 5.5 comes with an incredible new feature for making safe, asynchronous, concurrent code with async/await and Structured Concurrency. In this series we will cover each of these topics in depth, starting from the basics and moving on to more complex concurrency topics using actors.
Length: about 3 hours
In this episode we will show how the async await keyword can simplify asynchronous code, reading top-down as if it were synchronous, but without blocking any threads. We'll also see how async let can allow you to process multiple values concurrently.
In this episode we will see how we can run tasks concurrently with concurrent for loops, which is useful when the number of items you want to process is dynamic. With Task Groups you can process results asynchronously and assemble the results in a safe way.
In this episode we will see how URLSession can be used with async await. With this new API you can easily send network request and await a tuple of both the data and the response object.
With Continuations we can bridge the non-async world and make it async. Continuations allow us to take the result of a completion block and turn it into an async flow. In this episode we will see the difference between checked and unchecked continuations as well as their throwing variants.
Continuations are great for adapting completion-handler APIs to the new async await world. But what about delegate callbacks, which happen in an entirely separate method? In this episode we will adapt 2 delegate APIs into async await to see how this works.
Actors are a new first class concept in swift. In this episode we will explore the problem they solve and how to use them to avoid race conditions which can lead to inconsistent results or even crashes.
The unit of work in Swift Concurrency is the Task. In this episode we will see how tasks are created and structured, how to run work in parallel, and how to handle cancellation by aborting work or returning partial results.
In this episode we will see how to create and use our own AsyncSequence, which allow us to iterate over values that can arrive asynchronously. We'll see how this compares to traditional sequences and how to make use of AsyncIterator to build our own AsyncSequence implementations.
We explore how we might encapsulate logic within an AsyncSequence and introduce the need for a type erased version. Type-erasure has some pros and cons and in this video we will explore how to create one called AnyAsyncSequence and how we can use it.
In this episode we will look at two ways of generating async values with AsyncStream. We'll examine the difference between the push and pull models and how to deal with back pressure.
In this episode we create an image cache using an actor that provides disk-caching for images from the Unsplash API. We'll also talk about Sendable and enable some compiler warnings to help us catch potential issues.