pub struct SupervisorHandle<W: Worker> { /* private fields */ }Expand description
Handle used to interact with a running supervisor tree.
Implementations§
Source§impl<W: Worker> SupervisorHandle<W>
impl<W: Worker> SupervisorHandle<W>
Sourcepub fn start(spec: SupervisorSpec<W>) -> Self
pub fn start(spec: SupervisorSpec<W>) -> Self
Spawns a supervisor tree based on the provided specification.
Sourcepub async fn start_child(
&self,
id: impl Into<String>,
factory: impl Fn() -> W + Send + Sync + 'static,
restart_policy: RestartPolicy,
) -> Result<ChildId, SupervisorError>
pub async fn start_child( &self, id: impl Into<String>, factory: impl Fn() -> W + Send + Sync + 'static, restart_policy: RestartPolicy, ) -> Result<ChildId, SupervisorError>
Dynamically starts a new child worker
§Errors
Returns an error if the supervisor is shutting down or a child with this ID already exists.
Sourcepub async fn start_child_linked(
&self,
id: impl Into<String>,
factory: impl Fn() -> W + Send + Sync + 'static,
restart_policy: RestartPolicy,
timeout: Duration,
) -> Result<ChildId, SupervisorError>
pub async fn start_child_linked( &self, id: impl Into<String>, factory: impl Fn() -> W + Send + Sync + 'static, restart_policy: RestartPolicy, timeout: Duration, ) -> Result<ChildId, SupervisorError>
Dynamically starts a new child worker with linked initialization.
This method waits for the worker’s initialization to complete before returning. If initialization fails or times out, an error is returned and the worker is not added.
§Arguments
id- Unique identifier for the childfactory- Factory function to create the workerrestart_policy- How to handle worker termination after it starts runningtimeout- Maximum time to wait for initialization
§Errors
SupervisorError::InitializationFailed- Worker initialization returned an errorSupervisorError::InitializationTimeout- Worker didn’t initialize within timeoutSupervisorError::ChildAlreadyExists- A child with this ID already existsSupervisorError::ShuttingDown- Supervisor is shutting down
§Note
Initialization failures do NOT trigger restart policies. The worker must successfully initialize before restart policies take effect.
Sourcepub async fn terminate_child(&self, id: &str) -> Result<(), SupervisorError>
pub async fn terminate_child(&self, id: &str) -> Result<(), SupervisorError>
Dynamically terminates a child
§Errors
Returns an error if the child is not found or the supervisor is shutting down.
Sourcepub async fn which_children(&self) -> Result<Vec<ChildInfo>, SupervisorError>
pub async fn which_children(&self) -> Result<Vec<ChildInfo>, SupervisorError>
Sourcepub async fn shutdown(&self) -> Result<(), SupervisorError>
pub async fn shutdown(&self) -> Result<(), SupervisorError>
Requests a graceful shutdown of the supervisor tree.
§Errors
Returns an error if the supervisor channel is already closed.
Sourcepub async fn restart_strategy(&self) -> Result<RestartStrategy, SupervisorError>
pub async fn restart_strategy(&self) -> Result<RestartStrategy, SupervisorError>
Returns the supervisor’s restart strategy.
§Errors
Returns an error if the supervisor is shutting down.
Trait Implementations§
Source§impl<W: Clone + Worker> Clone for SupervisorHandle<W>
impl<W: Clone + Worker> Clone for SupervisorHandle<W>
Source§fn clone(&self) -> SupervisorHandle<W>
fn clone(&self) -> SupervisorHandle<W>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl<W> Freeze for SupervisorHandle<W>
impl<W> RefUnwindSafe for SupervisorHandle<W>
impl<W> Send for SupervisorHandle<W>
impl<W> Sync for SupervisorHandle<W>
impl<W> Unpin for SupervisorHandle<W>
impl<W> UnsafeUnpin for SupervisorHandle<W>
impl<W> UnwindSafe for SupervisorHandle<W>
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.