pub trait Node: Send + Sync {
    // Required method
    fn iteration<'life0, 'async_trait>(
        &'life0 self
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn on_resume<'life0, 'async_trait>(
        &'life0 self
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn on_abort<'life0, 'async_trait>(
        &'life0 self
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

The Node trait, shared among all node types, dictates how a node runs.

§Iteration

The central method, for which there is no default implementation, is iteration. This method is called, in a loop, by the Zenoh-Flow runtime managing the node.

Method in this trait takes an immutable reference to self so as to not impact performance. To keep a state and to mutate it, the interior mutability pattern is necessary.

For usage examples see the Operator, Source or Sink traits.

§Additional hooks: on_resume, on_abort

It is possible to define specific code that the Zenoh-Flow runtime should run before the node is aborted and before it is resumed.

Note that the on_resume hook is only run once the node has been aborted. It is not run when it is created.

A default blank implementation is provided.

Required Methods§

source

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

The code a Zenoh-Flow runtime will execute in a loop.

A typical workflow would be to wait for all or a subset of the Input(s) to be ready, perform some computation and finally forward the result(s) downstream on the Output(s).

Provided Methods§

source

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

Custom code that Zenoh-Flow will run before re-starting a node that was previously aborted.

The code to correctly manage the state of a node should go there. This hook is for instance leveraged within the implementation of the Zenoh Source built-in node.

The blanket implementation defaults to returning Ok(()).

§Performance

This method is only called when the node is restarted. Hence, its impact is limited and does not affect the normal execution of a node.

source

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

Implementors§