pub struct SupervisorHandle { /* private fields */ }Expand description
A handle for spawning dynamic children on a running Supervisor.
Obtained from Supervisor::handle. Handles are cheap to clone and can be shared across tasks. Spawning is async:
the request is handed to the running supervisor and the call returns once the child has been started. If the
supervisor isn’t currently running, spawning returns SpawnError::SupervisorGone.
Implementations§
Source§impl SupervisorHandle
impl SupervisorHandle
Sourcepub async fn spawn<T: Supervisable + 'static>(
&self,
worker: T,
) -> Result<ChildId, SpawnError>
pub async fn spawn<T: Supervisable + 'static>( &self, worker: T, ) -> Result<ChildId, SpawnError>
Spawns a new dynamic worker.
Dynamic workers are temporary children that are not restarted by the supervisor when they die or when the supervisor itself is restarted. They are useful for short-lived, non-critical background tasks that require structured concurrency: the process should be cancelled when the supervisor itself is restarted or terminated, and so on.
Use spawn_with to configure the child’s restart policy or significance.
§Errors
If the supervisor isn’t current running, or if the child specification is invalid, an error is returned.
Sourcepub async fn spawn_with(
&self,
spec: ChildSpecification<WorkerSpec>,
) -> Result<ChildId, SpawnError>
pub async fn spawn_with( &self, spec: ChildSpecification<WorkerSpec>, ) -> Result<ChildId, SpawnError>
Spawns a new dynamic child from a fully configured ChildSpecification.
Dynamic workers are temporary children that are not restarted by the supervisor when they die or when the supervisor itself is restarted. They are useful for short-lived, non-critical background tasks that require structured concurrency: the process should be cancelled when the supervisor itself is restarted or terminated, and so on.
This method allows for configuring more advanced aspects of the child process, such as its restart type and significance.
§Errors
If the supervisor isn’t current running, or if the child specification is invalid, an error is returned.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Returns whether the supervisor is currently running.
Sourcepub fn active_children(&self) -> usize
pub fn active_children(&self) -> usize
Returns the number of dynamic children currently running under the supervisor.
Trait Implementations§
Source§impl Clone for SupervisorHandle
impl Clone for SupervisorHandle
Source§fn clone(&self) -> SupervisorHandle
fn clone(&self) -> SupervisorHandle
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for SupervisorHandle
impl RefUnwindSafe for SupervisorHandle
impl Send for SupervisorHandle
impl Sync for SupervisorHandle
impl Unpin for SupervisorHandle
impl UnsafeUnpin for SupervisorHandle
impl UnwindSafe for SupervisorHandle
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
impl<T> CloneAny for 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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> Track for T
impl<T> Track for T
§fn track_resources(self, token: ResourceGroupToken) -> Tracked<Self>
fn track_resources(self, token: ResourceGroupToken) -> Tracked<Self>
Tracked wrapper. Read more§fn in_current_resource_group(self) -> Tracked<Self>
fn in_current_resource_group(self) -> Tracked<Self>
Tracked wrapper. Read more