pub trait RunnableTask: Send {
// Required methods
fn run(
&mut self,
watcher: &mut StateWatcher,
) -> impl Future<Output = TaskNextAction> + Send;
fn shutdown(self) -> impl Future<Output = Result<()>> + Send;
}
Expand description
The trait is implemented by the service task and contains a single iteration of the infinity loop.
Required Methods§
Sourcefn run(
&mut self,
watcher: &mut StateWatcher,
) -> impl Future<Output = TaskNextAction> + Send
fn run( &mut self, watcher: &mut StateWatcher, ) -> impl Future<Output = TaskNextAction> + Send
This function should contain the main business logic of the service task. It will run until
the service either returns false, panics or a stop signal is received.
If the service returns an error, it will be logged and execution will resume.
This is intended to be called only by the ServiceRunner
.
The ServiceRunner
continue to call the run
method in the loop while the state is
State::Started
. So first, the run
method should return a value, and after, the service
will stop. If the service should react to the state change earlier, it should handle it in
the run
loop on its own. See StateWatcher::while_started
.
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.