Struct smolscale::Nursery [−][src]
pub struct Nursery { /* fields omitted */ }
Expand description
A nursery represents a dynamic scope in which tasks can be spawned. It is used for structured concurrency, and it ensures that tasks spawned within the nursery terminate before the nursery falls out of scope.
We intentionally force all futures spawned in the nursery to return anyhow::Result<()>
, and we do not expose join handles. This encourages a CSP-style anonymous-process way of thinking, and integration with anyhow
allows for powerful error-propagation techniques.
Spawning is done through a NurseryHandle, which is clonable, rather than the Nursery itself. Nursery Deref
’s into a NurseryHandle
so that you can spawn from Nursery as well.
Implementations
To handle
Waits for the tasks in the nursery to terminate. If any errors are propagated, immediately returns the error, terminating the whole nursery.
This function asynchronously blocks until all NurseryHandles are dropped.
Methods from Deref<Target = NurseryHandle>
Spawns a task in the nursery, using the given recovery strategy. Takes a closure that returns a future because the task may be restarted on failure.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Nursery
impl UnwindSafe for Nursery