© Andrés Ibañez Kautsch 2023
A. I. KautschModern Concurrency on Apple Platformshttps://doi.org/10.1007/978-1-4842-8695-1_6

6. Actors

Andrés Ibañez Kautsch1  
(1)
La Paz, Bolivia
 

So far, we have covered about writing concurrent code in Swift using tasks that are independent of each other. You run some tasks, and oftentimes deliver the results to the main thread. But there are cases in which you need to have shared mutable state in your program – a common mutable source that your code can read from and write to. This source can be a simple variable, or it can be a file, or it can be any other kind of resource that is dangerous to access concurrently, yet it needs to be available to multiple tasks at the same time.

If you have multiple pieces of code ...

Get Modern Concurrency on Apple Platforms: Using async/await with Swift now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.