-
Awaiting Simple Async Function
- Write an
async
function that returns a greeting string. - Test that it returns the expected value using
#expect
.
- Write an
-
Async Throwing Function
- Create an
async throws
function that parses an integer from a string. - Test both successful and throwing behavior.
- Create an
-
Async Let Parallelism
- Run two async sleep operations in parallel using
async let
. - Test that the elapsed time confirms parallelism.
- Run two async sleep operations in parallel using
-
Simple Actor for Counter
- Create an actor that safely increments a counter.
- Test concurrent increments and final value.
-
Async Sequence Using
AsyncStream
- Create an
AsyncStream
that emits numbers 1 to 5. - Consume it and test that all values are received in order.
- Create an
-
Task Group Summation
- Use
withTaskGroup
to sum an array of integers in parallel. - Test with a known set and assert correct result.
- Use
-
Cooperative Cancellation
- Use
Task.checkCancellation()
inside a loop. - Test cancellation by cancelling the task early and ensuring partial results or failure.
- Use
-
MainActor vs nonisolated
- Create a type isolated to
MainActor
with anonisolated
logging method. - Test thread correctness using
Task.detached
.
- Create a type isolated to
-
Actor with Private Mutable State
- Build a
BankAccount
actor with deposit and balance-check methods. - Test that simultaneous deposits produce the correct total.
- Build a
-
Bridging Delegate to AsyncStream
- Bridge a fake delegate-style API to an
AsyncStream
. - Test by simulating callback invocations.
- Bridge a fake delegate-style API to an
-
Using Task Detachment
- Launch a detached task to do background processing and return a result.
- Test with a simulated background operation.
-
Bindables with Observable Macro
- Define a
@Observable
model and bind a property with@Bindable
. - Test changes propagate via a mock view model update.
- Define a
-
Nested Task Groups with Result Aggregation
- Compose task groups that download batches of data concurrently.
- Test with mock inputs and aggregate results.
-
Handling Sendable Violations
- Define a class that fails
Sendable
, then fix it using isolation orfinal
. - Test compilation with strict concurrency and validate no warnings.
- Define a class that fails
-
Unstructured Task Lifetime
- Start an unstructured task and manage its lifecycle manually.
- Test that cancellation and value retrieval work as expected.
-
Timeout Handling with
Task
- Implement a timeout mechanism using
Task.sleep
. - Test both success and timeout behavior.
- Implement a timeout mechanism using
-
Async Sequence Transformer
- Write a utility that takes any
AsyncSequence
and returns a new one with transformed values. - Test using
AsyncStream
as input and collect the transformed output.
- Write a utility that takes any
-
Using
withTaskCancellationHandler
- Simulate a task with clean-up logic triggered upon cancellation.
- Test the order of operations during cancellation.
-
Actor Isolation Violation Fix
- Try to mutate an actor's property from outside and fix the violation by refactoring with isolated methods.
- Confirm through compiler and test validation.
-
Testable Concurrency Pipeline
- Build a pipeline with async stages (e.g., fetch, transform, cache).
- Use actors or
TaskGroup
as needed. - Write end-to-end tests validating correctness under concurrency and cancellation.