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
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
Sourcepub async fn which_children(&self) -> Result<Vec<ChildInfo>, SupervisorError>
pub async fn which_children(&self) -> Result<Vec<ChildInfo>, SupervisorError>
Returns information about all children
Sourcepub async fn shutdown(&self) -> Result<(), SupervisorError>
pub async fn shutdown(&self) -> Result<(), SupervisorError>
Requests a graceful shutdown of the supervisor tree.
Sourcepub async fn restart_strategy(&self) -> Result<RestartStrategy, SupervisorError>
pub async fn restart_strategy(&self) -> Result<RestartStrategy, SupervisorError>
Returns the supervisor’s restart strategy.
Sourcepub async fn uptime(&self) -> Result<u64, SupervisorError>
pub async fn uptime(&self) -> Result<u64, SupervisorError>
Returns the supervisor’s uptime in seconds.
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>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
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> UnwindSafe for SupervisorHandle<W>
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
Returns the layout of the type.
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
Returns whether the given value has been niched. Read more
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
Writes data to
out indicating that a T is niched.