[][src]Struct smolscale::Nursery

pub struct Nursery { /* fields omitted */ }

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

impl Nursery[src]

pub fn new() -> Self[src]

Creates a new nursery

pub fn handle(&self) -> NurseryHandle[src]

To handle

pub async fn wait(self) -> Result<()>[src]

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.

pub fn wait_sync(self) -> Result<()>[src]

Helper function that waits for nursery tasks synchronously.

Methods from Deref<Target = NurseryHandle>

pub fn spawn<F: Future<Output = Result<()>> + Send + 'static>(
    &self,
    on_error: OnError,
    task_gen: impl FnOnce(NurseryHandle) -> F + Send + 'static
)
[src]

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

impl Default for Nursery[src]

impl Deref for Nursery[src]

type Target = NurseryHandle

The resulting type after dereferencing.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.