Skip to main content

ExecutorPerform

Trait ExecutorPerform 

Source
pub trait ExecutorPerform<X>: Send + Sync {
    // Required methods
    fn spawn_in_context<'async_trait, F>(
        future: F,
    ) -> Pin<Box<dyn Future<Output = Result<Arc<dyn Task<F::Output, Output = F::Output>>, SpawnError>> + Send + 'async_trait>>
       where F: Future + Send + 'static + 'async_trait,
             F::Output: Send + 'static;
    fn spawn_from_executor<'life0, 'async_trait, E, F>(
        executor: &'life0 E,
        future: F,
    ) -> Pin<Box<dyn Future<Output = Result<Arc<dyn Task<F::Output, Output = F::Output>>, SpawnError>> + Send + 'async_trait>>
       where E: Executor<X> + 'async_trait,
             F: Future + Send + 'static + 'async_trait,
             F::Output: Send + 'static,
             'life0: 'async_trait;
    fn block_from_executor<'life0, 'async_trait, E, F>(
        executor: &'life0 E,
        future: F,
    ) -> Pin<Box<dyn Future<Output = F::Output> + Send + 'async_trait>>
       where E: Executor<X> + 'async_trait,
             F: Future + Send + 'static + 'async_trait,
             F::Output: Send + 'static,
             'life0: 'async_trait;
    fn spawn_in_context_sync<F>(
        future: F,
    ) -> Result<Arc<dyn Task<F::Output, Output = F::Output>>, SpawnError>
       where F: Future + Send + 'static,
             F::Output: Send + 'static;
    fn spawn_from_executor_sync<E, F>(
        executor: &E,
        future: F,
    ) -> Result<Arc<dyn Task<F::Output, Output = F::Output>>, SpawnError>
       where E: Executor<X>,
             F: Future + Send + 'static,
             F::Output: Send + 'static;
    fn block_from_executor_sync<E, F>(executor: &E, future: F) -> F::Output
       where E: Executor<X>,
             F: Future + Send + 'static,
             F::Output: Send + 'static;
}
Expand description

Trait for spawning and managing async tasks.

This trait provides methods for spawning tasks on an executor and blocking on futures. It complements the Executor trait by focusing on task execution.

§Type Parameters

  • X - The executor handle type

§Examples

use product_os_async_executor::{ExecutorPerform, TokioExecutor};

#[tokio::main]
async fn main() {
    let task = TokioExecutor::spawn_in_context(async {
        println!("Hello from spawned task!");
        42
    }).await;
     
    assert!(task.is_ok());
}

Required Methods§

Source

fn spawn_in_context<'async_trait, F>( future: F, ) -> Pin<Box<dyn Future<Output = Result<Arc<dyn Task<F::Output, Output = F::Output>>, SpawnError>> + Send + 'async_trait>>
where F: Future + Send + 'static + 'async_trait, F::Output: Send + 'static,

Spawns a task in the current context asynchronously.

§Errors

Returns an error if the task cannot be spawned.

Source

fn spawn_from_executor<'life0, 'async_trait, E, F>( executor: &'life0 E, future: F, ) -> Pin<Box<dyn Future<Output = Result<Arc<dyn Task<F::Output, Output = F::Output>>, SpawnError>> + Send + 'async_trait>>
where E: Executor<X> + 'async_trait, F: Future + Send + 'static + 'async_trait, F::Output: Send + 'static, 'life0: 'async_trait,

Spawns a task from an executor asynchronously.

§Errors

Returns an error if the task cannot be spawned.

Source

fn block_from_executor<'life0, 'async_trait, E, F>( executor: &'life0 E, future: F, ) -> Pin<Box<dyn Future<Output = F::Output> + Send + 'async_trait>>
where E: Executor<X> + 'async_trait, F: Future + Send + 'static + 'async_trait, F::Output: Send + 'static, 'life0: 'async_trait,

Blocks on a future using the executor.

This method blocks the current thread until the future completes.

Source

fn spawn_in_context_sync<F>( future: F, ) -> Result<Arc<dyn Task<F::Output, Output = F::Output>>, SpawnError>
where F: Future + Send + 'static, F::Output: Send + 'static,

Spawns a task in the current context synchronously.

§Errors

Returns an error if the task cannot be spawned.

Source

fn spawn_from_executor_sync<E, F>( executor: &E, future: F, ) -> Result<Arc<dyn Task<F::Output, Output = F::Output>>, SpawnError>
where E: Executor<X>, F: Future + Send + 'static, F::Output: Send + 'static,

Spawns a task from an executor synchronously.

§Errors

Returns an error if the task cannot be spawned.

Source

fn block_from_executor_sync<E, F>(executor: &E, future: F) -> F::Output
where E: Executor<X>, F: Future + Send + 'static, F::Output: Send + 'static,

Blocks on a future using the executor synchronously.

This method blocks the current thread until the future completes.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§