pub struct SupervisorHandle { /* private fields */ }
Expand description
Handle used to interact with the Supervisor
.
Implementations§
Source§impl SupervisorHandle
impl SupervisorHandle
Sourcepub async fn wait(self) -> Result<Result<(), SupervisorError>, JoinError>
pub async fn wait(self) -> Result<Result<(), SupervisorError>, JoinError>
Waits for the supervisor to complete its execution.
This method consumes the handle and waits for the supervisor task to finish. It should be called only once per handle, as it takes ownership of the join handle.
§Returns
Ok(())
if the supervisor completed successfully.Err(JoinError)
if the supervisor task panicked.
§Panics
Panics if wait()
has already been called on any clone of this handle.
Sourcepub fn add_task<T: CloneableSupervisedTask + 'static>(
&self,
task_name: &str,
task: T,
) -> Result<(), SupervisorHandleError>
pub fn add_task<T: CloneableSupervisedTask + 'static>( &self, task_name: &str, task: T, ) -> Result<(), SupervisorHandleError>
Adds a new task to the supervisor.
This method sends a message to the supervisor to add a new task with the specified name.
§Arguments
task_name
: The unique name of the task.task
: The task to be added, which must implementSupervisedTask
.
§Returns
Ok(())
if the message was sent successfully.Err(SendError)
if the supervisor is no longer running.
Sourcepub fn restart(&self, task_name: &str) -> Result<(), SupervisorHandleError>
pub fn restart(&self, task_name: &str) -> Result<(), SupervisorHandleError>
Requests the supervisor to restart a specific task.
This method sends a message to the supervisor to restart the task with the given name.
§Arguments
task_name
: The name of the task to restart.
§Returns
Ok(())
if the message was sent successfully.Err(SendError)
if the supervisor is no longer running.
Sourcepub fn shutdown(&self) -> Result<(), SupervisorHandleError>
pub fn shutdown(&self) -> Result<(), SupervisorHandleError>
Requests the supervisor to shut down all tasks and stop supervision.
This method sends a message to the supervisor to terminate all tasks and cease operation.
§Returns
Ok(())
if the message was sent successfully.Err(SendError)
if the supervisor is no longer running.
Sourcepub async fn get_task_status(
&self,
task_name: &str,
) -> Result<Option<TaskStatus>, SupervisorHandleError>
pub async fn get_task_status( &self, task_name: &str, ) -> Result<Option<TaskStatus>, SupervisorHandleError>
Queries the status of a specific task asynchronously.
This method sends a request to the supervisor to retrieve the status of the specified task and awaits the response.
§Arguments
task_name
: The name of the task to query.
§Returns
Ok(Some(TaskStatus))
if the task exists and its status is returned.Ok(None)
if the task does not exist.Err(RecvError)
if communication with the supervisor fails (e.g., it has shut down).
Sourcepub async fn get_all_task_statuses(
&self,
) -> Result<HashMap<String, TaskStatus>, SupervisorHandleError>
pub async fn get_all_task_statuses( &self, ) -> Result<HashMap<String, TaskStatus>, SupervisorHandleError>
Queries the statuses of all tasks asynchronously.
This method sends a request to the supervisor to retrieve the statuses of all tasks and awaits the response.
§Returns
Ok(HashMap<TaskName, TaskStatus>)
containing the statuses of all tasks.Err(RecvError)
if communication with the supervisor fails (e.g., it has shut down).
Trait Implementations§
Source§impl Clone for SupervisorHandle
impl Clone for SupervisorHandle
Source§fn clone(&self) -> SupervisorHandle
fn clone(&self) -> SupervisorHandle
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more