spawn

Function spawn 

Source
pub fn spawn<S, T>(child: T) -> ChildId
Expand description

Spawns a child on the ambient supervisor.

The ambient supervisor is the one supervising the currently running process, so the child becomes a sibling of the caller rather than its descendant.

Accepts anything Supervisor::add_worker accepts: a bare Supervisable, a Supervisor to run as a nested supervision subtree, or a ChildSpecification configured in detail. Unless the specification says otherwise, the child is temporary; see SupervisorHandle::spawn for what that implies.

This mirrors tokio::spawn in both shape and guarantees: it always succeeds, and success means the child was accepted, not that it will run. A supervisor that shuts down before it reaches the queued child never starts it.

§Panics

Panics if there is no ambient supervisor, which means the caller isn’t running as (or within) a supervised process. Establish one with SupervisorHandle::scope, or spawn through a SupervisorHandle directly.

§Examples

spawn(FnWorker::new("refresher", refresh()));