Group Group Group Group Group Group Group Group Group Group Shape Group Group Group Group Group Group Group Group Group Group Group Group Group Group Group Group Group Group Group Group Group Group Group Group Group Group Group Group Group Group Group Group Group Group Group Group Group
Skip to Content
  • iii. Dedications
  • More
    • NewsletterNewsletter
    • ForumsForums
Sign In
Create a free account
  • Search
  • Notebook
  • Customise
Pro

Modern Concurrency in Swift

First Edition Swift 5.5, iOS 15, Xcode 13

Before You Begin

Section 0: 6 chapters
  • i. What You Need
  • ii. Book Source Code & Forums
  • iii. Dedications
  • iv. About the Team
  • v. Acknowledgments
  • vi. Introduction
    • How to read this book

Section I: Modern Concurrency in Swift

Section 1: 11 chapters
  • 1. Why Modern Swift Concurrency?
    • 1.1 Understanding asynchronous and concurrent code
    • 1.2 Introducing the modern Swift concurrency model
    • 1.3 Running the book server
    • 1.4 Getting started with LittleJohn
    • 1.5 Writing your first async/await
    • 1.6 Using async/await in SwiftUI
    • 1.7 Using asynchronous sequences
    • 1.8 Canceling tasks in structured concurrency
    • 1.9 Handling cancellation errors
    • 1.10 Challenges
    • 1.11 Key points
  • 2. Getting Started With async/await
    • 2.1 Pre-async/await asynchrony
    • 2.2 Separating code into partial tasks
    • 2.3 Controlling a task’s lifetime
    • 2.4 Getting started
    • 2.5 A bird’s eye view of async/await
    • 2.6 Getting the list of files from the server
    • 2.7 Getting the server status
    • 2.8 Grouping asynchronous calls
    • 2.9 Asynchronously downloading a file
    • 2.10 Running async requests from a non-async context
    • 2.11 A quick detour through Task
    • 2.12 Routing code to the main thread
    • 2.13 Updating the download screen’s progress
    • 2.14 Challenges
    • 2.15 Key points
  • 3. AsyncSequence & Intermediate Task
    • 3.1 Getting to know AsyncSequence
    • 3.2 Getting started with AsyncSequence
    • 3.3 Canceling tasks
    • 3.4 Canceling an async task
    • 3.5 Manually canceling tasks
    • 3.6 Storing state in tasks
    • 3.7 Bridging Combine and AsyncSequence
    • 3.8 Challenges
    • 3.9 Key points
  • 4. Custom Asynchronous Sequences With AsyncStream
    • 4.1 Getting started with the Blabber app
    • 4.2 Digging into AsyncSequence, AsyncIteratorProtocol and AsyncStream
    • 4.3 Creating an asynchronous timer with AsyncStream
    • 4.4 Adding an asynchronous stream to NotificationCenter
    • 4.5 Extending AsyncSequence
    • 4.6 Challenges
    • 4.7 Key points
  • 5. Intermediate async/await & CheckedContinuation
    • 5.1 Introducing continuations
    • 5.2 Creating continuations manually
    • 5.3 Wrapping the delegate pattern
    • 5.4 Wrapping callback APIs with continuation
    • 5.5 Challenges
    • 5.6 Key points
  • 6. Testing Asynchronous Code
    • 6.1 Capturing network calls under test
    • 6.2 Creating a model for testing
    • 6.3 Adding a simple asynchronous test
    • 6.4 Testing values over time with AsyncStream
    • 6.5 Adding TimeoutTask for safer testing
    • 6.6 Using async let to produce effects and observe them at the same time
    • 6.7 Speeding up asynchronous tests
    • 6.8 Key points
  • 7. Concurrent Code With TaskGroup
    • 7.1 Introducing TaskGroup
    • 7.2 Getting started with Sky
    • 7.3 Spawning tasks in a simple loop
    • 7.4 Creating a concurrent task group
    • 7.5 Controlling task execution
    • 7.6 Getting results from a task group
    • 7.7 Mutating shared state
    • 7.8 Processing task results in real time
    • 7.9 Controlling the group flow
    • 7.10 Running code after all tasks have completed
    • 7.11 Group error handling
    • 7.12 Using the Result type with TaskGroup
    • 7.13 Key points
  • 8. Getting Started With Actors
    • 8.1 Understanding thread-safe code
    • 8.2 Meeting actor
    • 8.3 Recognizing the main actor
    • 8.4 Getting started with actors
    • 8.5 Mutating state concurrently
    • 8.6 Showing the art and updating the progress
    • 8.7 Detecting race conditions
    • 8.8 Using actors to protect shared mutable state
    • 8.9 Sharing data across actors
    • 8.10 Understanding Sendable
    • 8.11 Making safe methods nonisolated
    • 8.12 Designing more complex actors
    • 8.13 Sharing the actor
    • 8.14 Key points
  • 9. Global Actors
    • 9.1 Getting to meet GlobalActor
    • 9.2 Continuing with the EmojiArt project
    • 9.3 Creating a global actor
    • 9.4 Creating a safe silo
    • 9.5 Initializing the database actor
    • 9.6 Writing files to disk
    • 9.7 Fetching images from disk (or elsewhere)
    • 9.8 Purging the cache
    • 9.9 Wiring up the persistence layer
    • 9.10 Adding a cache hit counter
    • 9.11 Displaying the counter
    • 9.12 Purging the in-memory cache
    • 9.13 Challenges
    • 9.14 Key points
  • 10. Actors in a Distributed System
    • 10.1 Going from local to distributed
    • 10.2 Getting started with SkyNet
    • 10.3 Enabling the network layer
    • 10.4 Creating an actor system
    • 10.5 Connecting to remote systems
    • 10.6 Adding a connectivity indicator
    • 10.7 Sending a task to a remote system
    • 10.8 Managing a network request lifetime
    • 10.9 Receiving a response from a remote system
    • 10.10 Executing requests from other systems
    • 10.11 Sending a result back
    • 10.12 Handling incoming data
    • 10.13 Putting everything together
    • 10.14 Adding some UI bling
    • 10.15 Retrying failed tasks
    • 10.16 Key points
    • 10.17 Where to go from here?
  • 11. Conclusion
Home iOS & Swift Books Modern Concurrency in Swift

iii
Dedications

“Dedicated to my daughter and family. Warm thanks to everyone on the extended team that made this book possible.”

— Marin Todorov

iv. About the Team ii. Book Source Code & Forums

Have a technical question? Want to report a bug? You can ask questions and report bugs to the book authors in our official book forum here.

© 2022 Razeware LLC