AsyncEngineContext

Trait AsyncEngineContext 

Source
pub trait AsyncEngineContext:
    Send
    + Sync
    + Debug {
    // Required methods
    fn id(&self) -> &str;
    fn is_stopped(&self) -> bool;
    fn is_killed(&self) -> bool;
    fn stopped<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn killed<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn stop_generating(&self);
    fn stop(&self);
    fn kill(&self);
}
Expand description

The AsyncEngineContext trait defines the interface to control the resulting stream produced by the engine.

This trait provides lifecycle management for async operations, including:

  • Stream identification via unique IDs
  • Graceful shutdown capabilities (stop_generating)
  • Immediate termination capabilities (kill)
  • Status checking for stopped/killed states

Implementations should ensure thread-safety and proper state management across concurrent access patterns.

Required Methods§

Source

fn id(&self) -> &str

Unique ID for the Stream

Source

fn is_stopped(&self) -> bool

Returns true if stop_generating() has been called; otherwise, false.

Source

fn is_killed(&self) -> bool

Returns true if kill() has been called; otherwise, false. This can be used with a .take_while() stream combinator to immediately terminate the stream.

An ideal location for a [.take_while(!ctx.is_killed())] stream combinator is on the most downstream return stream.

Source

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

Calling this method when AsyncEngineContext::is_stopped is true will return immediately; otherwise, it will AsyncEngineContext::is_stopped will return true.

Source

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

Calling this method when AsyncEngineContext::is_killed is true will return immediately; otherwise, it will AsyncEngineContext::is_killed will return true.

Source

fn stop_generating(&self)

Informs the AsyncEngine to stop producing results for this particular stream. This method is idempotent. This method does not invalidate results current in the stream. It might take some time for the engine to stop producing results. The caller can decided to drain the stream or drop the stream.

Source

fn stop(&self)

Source

fn kill(&self)

Extends the AsyncEngineContext::stop_generating also indicates a preference to terminate without draining the remaining items in the stream. This is implementation specific and may not be supported by all engines.

Implementors§