1

The Swift Concurrency Story | Alexito's World

 2 years ago
source link: https://alejandromp.com/swift-concurrency/swift-concurrency-story/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

The Swift Concurrency Story

For years one the missing pieces of the language was the capability to deal with concurrency. It wasn't until 2017 when a Concurrency Manifesto for Swift was written by Chris Lattner. The manifesto got a lot of us excited. Personally I found it very interesting and eye opening that one of the possible directions was to do much more than just a basic support for concurrency.

We had to wait for 2020 to start seeing serious strikes at this. It was when we got the Road to Swift 6. With ABI stability behind the Core Team was able to focus on new horizons for Swift. It was time for Concurrency!

Even if the original manifesto was just one suggestion, the end result is quite similar. And as big if not bigger! That's one the first things you need to understand about the Swift Concurrency Story, is a big one, full of interconnected features all building on top of each other. It's a beautiful design but it's also a big overwhelming at first.

You can check this Twitter thread to get a feeling of how big the effort was and how many people was involved in it.

It's also important to note that this is still in flux. WWDC gave us the first beta of Xcode 13 which includes a preliminary version of Swift 5.5, which includes part of the entire story. APIs are still changing, some proposals are not even accepted yet, so don't worry if something is not perfect yet. The goal is to have a fully formed system by Swift 6. But it's already totally functional!

Swift Concurrency Story

Swift Concurrency

As you can see in the diagram there is a lot of parts that form the concurrency story. But don't feel overwhelemed, let's discuss what for me re the most important parts.

For me the best way of visualise this is just focus on the 4 pillars that form the Swift Concurrency Story: async/await, Structured Concurrency, Async Sequences and Actors.

We will discuss each pillar in detail but I just want to start by giving an overview of the structur

The first pillar is probably the most visible one: async/await. Everything else is build on top of this, but is very important to understand that on its own it has very little to do with concurrency. We will see what this means later.

The second in the list, and for me the most important of all, is structured concurrency. This on its own is an invisble feature, but the one that makes everything else work flawlessly, unlocking a huge potential of beautiful APIs. We will learn about the theory behind it and why is so much batter than the alternatives we had until now.

Async functions are ideal to return a single value, but in the same way we need arrays we also need async sequences. They are a very important concept when you need to get more than one value asyncronosly over time. It also matters because is probably the one that is most disrupting to existing solutions. We will have a lot to discuss about this!

And finally Actors. They are not a new concept on programming but is likely that you have heard very little of them. Usually they are used in distributed computing but Swift's implementation is ideal even for user facing applications. This is another topic where we will need to learn the theory behind it and compare it with how it has turned out in practice for Swift.

There are a lot of other topics to talk about but we will get there in time. First we need to learn the core of the story before we explore the rest of its ecosystem.

Swift Evolution Proposals

If you want to read the proposals that added the functionality to the language I leave here a list of all of them:


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK