pub trait Task: Send + 'static {
// Required method
fn shutdown(self) -> impl Future<Output = Result<()>> + Send;
}Expand description
A service or resource that can be shut down gracefully.
Implement this trait for every long-running component that needs cleanup on
process exit — HTTP servers, background workers, connection pools, etc.
The run! macro calls Task::shutdown on each registered
task in declaration order after a shutdown signal is received.
§Contract
- Implementors must be
Send + 'staticso they can be moved across threads. shutdownconsumesself— the task cannot be used after shutdown.- Return
Erronly for genuinely unexpected failures; normal teardown should returnOk(()).
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.