fuel_core_services

Trait RunnableTask

Source
pub trait RunnableTask: Send {
    // Required methods
    fn run<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        watcher: &'life1 mut StateWatcher,
    ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn shutdown<'async_trait>(
        self,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait;
}
Expand description

The trait is implemented by the service task and contains a single iteration of the infinity loop.

Required Methods§

Source

fn run<'life0, 'life1, 'async_trait>( &'life0 mut self, watcher: &'life1 mut StateWatcher, ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

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.

Source

fn shutdown<'async_trait>( self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,

Gracefully shutdowns the task after the end of the execution cycle.

Implementors§