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

Creates a new nursery

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.

Helper function that waits for nursery tasks synchronously.

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

Returns the “default value” for a type. Read more

The resulting type after dereferencing.

Dereferences the value.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.