pub struct TaskManager { /* private fields */ }
Expand description
The task manager is used similar to how in Go a WaitGroup is used. It provides us with the ability to gracefully shutdown the application giving the chance for each spawned task to gracefully exit during an idle moment.
Normally the graceful shutdown will be induced by a system signal (e.g. SIGINT), but spawned tasks can also induce it themselves if required for critical reasons.
Implementations§
Source§impl TaskManager
impl TaskManager
Sourcepub fn new(wait_timeout: Duration) -> Self
pub fn new(wait_timeout: Duration) -> Self
Create a new task manager. There should be only one manager per application.
pub fn task(&self) -> Task
Sourcepub async fn wait(self) -> bool
pub async fn wait(self) -> bool
Wait for all tasks to finish, or until the defined timeout has been reached.
Returns a boolean indicating if the shutdown was graceful.
Sourcepub async fn shutdown_gracefully_on_ctrl_c(self) -> bool
pub async fn shutdown_gracefully_on_ctrl_c(self) -> bool
Block the shutdown process until a CTRL+C signal has been received, and shutdown gracefully once received.
In case no tasks are active we will immediately return as well, preventing programs from halting in case infinite loop tasks exited early due to an error.
Returns a boolean indicating if the shutdown was graceful, or in case the process shut down early (no tasks = graceful by definition).