Skip to content

Latest commit

 

History

History
 
 

examples

Examples

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.

  1. resource_drop: All tasks get canceled when the NurseryStream goes out of scope. Works in functions and spawned tasks.
  2. resource_await: Wait for all tasks to finish. Works in functions and spawned tasks.
  3. resource_outlive: Let functions spawn on a nursery that outlives them.
  4. cancel_coop: Cooperative cancellation, if you can't afford being dropped at await points.
  5. cancel_coop_all: Cooperative cancellation through closing the Nursery for a special case.
  6. return_value: Use stream to evaluate all returned values.
  7. return_progress: Use stream to evaluate all returned values. A progress bar.
  8. return_error: Use TryStreamExt to bail as soon as one error happens.
  9. return_catch_unwind: Bail if any task panics, without panicking the current thread.
  10. subtask_ref: Pass references into function calls instead of cloning the Nursery.
  11. subtask_spawn: Let spawned tasks spawn subtasks on a nursery passed in.
  12. single-thread: It all works single threaded too. Spawn !Send tasks.
  13. timeout: Give tasks a maximum run time.
  14. wasm: It all works in wasm too.
  15. 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.
  16. tracing: Shows how to create and use an tracing instrumented nursery.