This is a demo project to practice Swift Structured Concurrency with multiple parts.
- BasicDemo: This demo will show some basic things like:
- The basic async await usage and how the executing thread will be. (although you shouldn't think of thread while using Structured Concurrency)
- async let
- The generic types of Task
- yield
- CancelDemo: This demo will show the following things:
- The isCancelled changes status when the parent task is canceled
- The isCancelled changes status when other Task throws an error
- GroupingTasksDemo:
- Just like the naming, this demo will show how to do grouping jobs.
- MainActorDemo:
- The order of execution
- @MainActor attribute for function and closure
- AsyncSequence
- AsyncMap for Sequence
- AsyncSequence & AsyncIteratorProtocol protocol
- AsyncStream & AsyncThrowingStream
-
onTermination
triggered when canceling - The implementations of
AsyncMapSequence
&AsyncThrowingCompactMapSequence.
- Implement a simple image downloader with the AsyncSequence
- Actor
- ActorDemo.playground: - MainActor - GlobalActor - Basic behaviors
- CustomActorExecutorDemo.playground:
- ActorReentrancyDemo.playground
- TaskLocal
- Basic behaviors of TaskLocal
- Some potential usages of TaskLocal
- AsyncResourceLimiter
- A simple implementation to limit async function execution at the same time.
- Some updates from Swift 5.9 for the Part II and III demonstrations
Part I: All demos work with their demo view, which is compatible with SwiftUI Preview. Please use the demo project in the following way:
- Place the demo view on the left side with the canvas, and the demo itself on the right.
- For example: BasicDemoView (left) / BasicDemo (right).
Part II: Most of the demos are triggered by the test cases, so please use the demo project in the following way:
- Place the demonstrations on the left side, and the test cases on the right.
- For example: AsyncSequenceDemo.swift (left) / AsyncSequenceDemoTest.swift (right)."
Part III: All demonstrations can be found in the following playground files:
- ActorDemo.playground
- CustomActorExecutorDemo.playground
- ActorReentrancyDemo.playground
Part IV: All demonstrations can be found in the following playground files:
- TaskLocalDemo.playground
- TaskLocalPlayground.playground
- ExecutingLimiter.playground
Simply highlight sections of the code and interact directly within the playground.