work at the same time — Async — Work that doesn't block the calling thread — Concurrency — Doing more than one piece of work at a time, with overlapping and non-overlapping work — Preventing unnessary waiting — Atomicity/atomic/non-atomic Atomicity is a safety measure which enforces that operations do not complete in an unpredictable way when accessed by multiple threads or processes simultaneously. — source 3
All async functions run as part of an async /task/ — Carry schedule info like priority and act as interface for cancellation and such — Try is written at call-site of the constant — On completion, the constants are initialized func makeDinner() async throws -> Meal { async let veggies = chopVegetables() async let meat = marinateMeat() async let oven = preheatOven() let dish = Dish(ingredients: await [try veggies, meat]) return await try oven.cook(dish) } 13
of limitations called actor isolation — For example, instance properties can only be accessed on self — Conversely, immutable value type properties don’t require isolation — To call an instance method that mutates self, make that method async 14
value types only — value types are true copies and not references to the original object in memory, therefore, safer to deal with 2. Then full isolation model — for state in reference types etc 15
updates — Enforce /actor isolation/ on mutable instance properties — Internally, each class instance has something like its own queue actor class BankAccount { // imagine this // private let backAccountQueue = DispatchQueue(name: "BankAccount", qos: .background) private let ownerName: String private var balance: Double // requires async func transfer(amount: Double, to other: BankAccount) async throws { balance = balance - amount await other.deposit(amount: amount) } } 16
specific class — Annotations that can be fixed to variables and functions — Singleton actor that only has one instance of a global actor in a given process — EG: @UIActor for main thread — actor classes on the other hand can have many instances // Usage @UIActor func showUsers() {} // Definition @globalActor struct UIActor { static let shared = SomeActorInstance() } 17
more — Rust — Borrow checker has great guarentees — Async/await, locks, channels — Verbose and less declarative (lower-level "older- brother" to Swift) — Source 19
making it even better for Apple GUI platform development — Apple's push for distributed systems — Swift's complexity will increase, so hopefully the pace will slow down after concurrency — Progressive disclosure helps — Worrying "Which feature to use?" is both a joy and a curse — Swift won't replace Go, Rust, Java, Ruby etc, but instead complement them more — More choice of concurrent-savvy languages is a win for us all — If successful on Swift, Actors may spread to new languages 22
— Async/await — Structured Concurrency — Actors & actor isolation — Actor memory isolation for “global” state — “Actors are reference types, but why classes?” — Evolving the Concurrency design and proposals — Merged code — Concurrency Roadmap͔Β֞ؒݟΔSwiftͷະདྷͷҰଆ໘ 24