These examples go over a number of different scenarios you might need in developing applications with structured concurrency. The links in this document point to examples illustrating the use case.
- resource_drop: All tasks get canceled when the
NurseryStream
goes out of scope. Works in functions and spawned tasks. - resource_await: Wait for all tasks to finish. Works in functions and spawned tasks.
- resource_outlive: Let functions spawn on a nursery that outlives them.
- cancel_coop: Cooperative cancellation, if you can't afford being dropped at await points.
- cancel_coop_all: Cooperative cancellation through closing the
Nursery
for a special case. - return_value: Use stream to evaluate all returned values.
- return_progress: Use stream to evaluate all returned values. A progress bar.
- return_error: Use TryStreamExt to bail as soon as one error happens.
- return_catch_unwind: Bail if any task panics, without panicking the current thread.
- subtask_ref: Pass references into function calls instead of cloning the
Nursery
. - subtask_spawn: Let spawned tasks spawn subtasks on a nursery passed in.
- single-thread: It all works single threaded too. Spawn !Send tasks.
- timeout: Give tasks a maximum run time.
- wasm: It all works in wasm too.
- type_bound: Shows how you can save a nursery on a struct, so it's life and that of all spawned tasks is bound to it. The example doesn't do anything when run.
- tracing: Shows how to create and use an tracing instrumented nursery.