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§
Sourcefn is_stopped(&self) -> bool
fn is_stopped(&self) -> bool
Returns true if stop_generating()
has been called; otherwise, false.
Sourcefn is_killed(&self) -> bool
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.
Sourcefn stopped<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
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.
Sourcefn killed<'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,
Calling this method when AsyncEngineContext::is_killed
is true
will return
immediately; otherwise, it will AsyncEngineContext::is_killed
will return true.
Sourcefn stop_generating(&self)
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.
Sourcefn kill(&self)
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.