pub struct Supervisor { /* private fields */ }Expand description
Owns the host’s background jobs over a single Spawn backend.
Implementations§
Source§impl Supervisor
impl Supervisor
Sourcepub fn new(spawn: Arc<dyn Spawn>) -> Self
pub fn new(spawn: Arc<dyn Spawn>) -> Self
Create a supervisor backed by spawn (production batpak::store::ThreadSpawn
or a test scheduler).
Sourcepub fn spawn(
&mut self,
name: impl Into<String>,
stack_size: Option<usize>,
body: Box<dyn FnOnce() + Send + 'static>,
) -> Result<(), SpawnError>
pub fn spawn( &mut self, name: impl Into<String>, stack_size: Option<usize>, body: Box<dyn FnOnce() + Send + 'static>, ) -> Result<(), SpawnError>
Spawn body as a named supervised job.
§Errors
SpawnError if the backing Spawn could not start the body.
Sourcepub fn job_count(&self) -> usize
pub fn job_count(&self) -> usize
Number of jobs the supervisor is tracking (finished or running).
Sourcepub fn statuses(&self) -> Vec<(String, JobStatus)>
pub fn statuses(&self) -> Vec<(String, JobStatus)>
The non-blocking status of every tracked job, in spawn order.
Sourcepub fn join_all(&mut self) -> Vec<(String, Result<(), JoinError>)>
pub fn join_all(&mut self) -> Vec<(String, Result<(), JoinError>)>
Join every tracked job, blocking until each finishes, and return each job’s name with its join outcome in spawn order. The supervisor is left empty.
A job whose body never returns blocks here forever — the generic supervisor cannot cancel a body it did not author. Modules that own long-lived work signal it to wind down from a shutdown hook (which the host runs before this join).
Auto Trait Implementations§
impl !RefUnwindSafe for Supervisor
impl !UnwindSafe for Supervisor
impl Freeze for Supervisor
impl Send for Supervisor
impl Sync for Supervisor
impl Unpin for Supervisor
impl UnsafeUnpin for Supervisor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more