Skip to main content

Executor

Trait Executor 

Source
pub trait Executor<X>: Send + Sync {
    // Required methods
    fn context<'async_trait>(    ) -> Pin<Box<dyn Future<Output = Result<Self, SpawnError>> + Send + 'async_trait>>
       where Self: Sized + 'async_trait;
    fn set_context<'life0, 'async_trait>(
        &'life0 mut self,
        executor: X,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn enter_context<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn get_executor<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = &X> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn context_sync() -> Result<Self, SpawnError>
       where Self: Sized;
    fn set_context_sync(&mut self, executor: X);
    fn enter_context_sync(&self);
    fn get_executor_sync(&self) -> &X;
}
Expand description

Trait for managing executor contexts across different async runtimes.

This trait provides a unified interface for creating, configuring, and accessing executor contexts regardless of the underlying async runtime (Tokio, Smol, etc.).

§Type Parameters

  • X - The executor handle type specific to the runtime (e.g., tokio::runtime::Handle)

§Examples

use product_os_async_executor::{Executor, TokioExecutor};

#[tokio::main]
async fn main() {
    let executor = TokioExecutor::context().await.unwrap();
    executor.enter_context().await;
}

Required Methods§

Source

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

Creates a new executor context asynchronously.

§Errors

Returns an error if the executor context cannot be created.

Source

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

Sets the executor context to the provided executor.

Source

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

Enters the executor context.

Source

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

Gets a reference to the underlying executor.

Source

fn context_sync() -> Result<Self, SpawnError>
where Self: Sized,

Creates a new executor context synchronously.

§Errors

Returns an error if the executor context cannot be created.

Source

fn set_context_sync(&mut self, executor: X)

Sets the executor context synchronously.

Source

fn enter_context_sync(&self)

Enters the executor context synchronously.

Source

fn get_executor_sync(&self) -> &X

Gets a reference to the underlying executor synchronously.

Implementors§