pub trait Supervisable: Send + Sync {
// Required methods
fn name(&self) -> &str;
fn initialize<'life0, 'async_trait>(
&'life0 self,
process_shutdown: ShutdownHandle,
) -> Pin<Box<dyn Future<Output = Result<SupervisorFuture, InitializationError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
// Provided methods
fn shutdown_strategy(&self) -> ShutdownStrategy { ... }
fn wants_shutdown_signal(&self) -> bool { ... }
fn can_restart(&self) -> bool { ... }
}Expand description
A supervisable process.
Required Methods§
Sourcefn initialize<'life0, 'async_trait>(
&'life0 self,
process_shutdown: ShutdownHandle,
) -> Pin<Box<dyn Future<Output = Result<SupervisorFuture, InitializationError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn initialize<'life0, 'async_trait>(
&'life0 self,
process_shutdown: ShutdownHandle,
) -> Pin<Box<dyn Future<Output = Result<SupervisorFuture, InitializationError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Initializes the process asynchronously.
During initialization, any resources or configuration for the process can be created asynchronously, and the
same runtime that’s used for running the process is used for initialization. The resulting future is expected to
complete as soon as reasonably possible after shutdown resolves.
Important: The process_shutdown signal must be moved into the returned SupervisorFuture so the worker
can respond to supervisor-initiated shutdown. If process_shutdown is dropped during initialization, the worker
will be unable to shut down gracefully and will be halted after the shutdown timeout.
§Errors
If the process can’t be initialized, an error is returned.
Provided Methods§
Sourcefn shutdown_strategy(&self) -> ShutdownStrategy
fn shutdown_strategy(&self) -> ShutdownStrategy
Returns the shutdown strategy for the process.
Sourcefn wants_shutdown_signal(&self) -> bool
fn wants_shutdown_signal(&self) -> bool
Returns whether this process observes the shutdown signal it is given.
The shutdown of a subtree is a trigger, not an enforcement. Many workers ignore the signal completely, and
stop only when they reach their own terminal condition, such as when an input channel closes. If this function
returns false, the supervisor gives the process a [ShutdownHandle::noop] instead. But the
scope of the process still observes the signal for the process, so that it can tell
whether an exit of one of its children was requested.
It also decides whether a nested supervisor in that scope that
stops with its owner is told to stop together with
the process. If this function returns false, the nested supervisor stops only when the scope closes.
This says nothing about whether the supervisor waits for the process – that’s
shutdown_strategy. A process that ignores the signal is still waited for, up to its
shutdown timeout.
Defaults to true.
Sourcefn can_restart(&self) -> bool
fn can_restart(&self) -> bool
Returns whether the process can be started again after it has started once.
initialize builds the future of the process each time the process starts. Most processes
can build it again, so their owner can restart them. A process that consumes something when it starts cannot
build its future a second time. Examples are a connection, or a value that the process received before it ran.
Such a process returns false here.
The owner of a process that returns false never restarts it, whatever restart policy the process has. When the
process stops, its owner reaps it, or fails if it needs the process. See the
runtime documentation for how this decides the restart policy.
Defaults to true.