Automaton

Trait Automaton 

Source
pub trait Automaton: Debug {
    // Required method
    fn initial_task(&self) -> Box<dyn Task>;

    // Provided methods
    fn initial_state(&self) -> State { ... }
    fn complete_task(&self) -> Box<dyn Task> { ... }
    fn execute<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<State, Error>> + Send + 'async_trait>>
       where Self: Sync + 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

Trait for automatons

Automatons execute a series of tasks. This trait defines the behavior that automatons must implement so that they can be executed inside a runtime.

Required Methods§

Source

fn initial_task(&self) -> Box<dyn Task>

Returns the first task in the automaton.

The initial task defines the entry point of the automaton. This task will be executed with the initial state.

Provided Methods§

Source

fn initial_state(&self) -> State

Returns the initial state for the execution.

Automatons can customize the state that is passed to the tasks. This can be useful to inject secrets or configuration on which tasks might depend. By default, an empty state is used.

Source

fn complete_task(&self) -> Box<dyn Task>

Returns the task that is called after the completed transition.

When a tasks returns Transition::Complete to end the execution of the automaton, a final task is executed. This can be useful to perform any teardown actions, for example to remove resources that were created in a previous step. By default, a “noop” task is executed that performs no action.

Source

fn execute<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<State, Error>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait,

Executes the automaton.

Automatons execute a series of tasks. When started, the automaton first initializes a new state. Then, it iterates over the list of tasks. It initializes and executes each task one by one until it either reaches the end of the list or a task returns Transition::Complete. In both instances, the task returned by the complete_task method is executed and the automaton shuts down.

Implementors§