Series: Async / Await

Async / Await

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

Installments

1. Async / Await Basics

Subscribers only

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.

2. Concurrent For Loops with Task Groups

Subscribers only

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.

3. Async Networking

Subscribers only

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.

4. Adapting existing asynchronous APIs with Continuations

Subscribers only

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.

5. Adapting Delegate Callbacks to Async Await

Subscribers only

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.

6. Actors

Subscribers only

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.

7. Tasks, Groups, and Cancellation

Subscribers only

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.

8. AsyncSequence

Subscribers only

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.

9. Type Erased Async Sequences

Subscribers only

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.

10. Async Streams

Subscribers only

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.

11. Creating an Actor-based Image Cache

Subscribers only

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.