Skip to main content

SpawnAsync

Trait SpawnAsync 

Source
pub trait SpawnAsync {
    // Required method
    fn spawn<F>(fut: F) -> impl Task<F::Output>
       where F: Future + Send + 'static,
             F::Output: Send + 'static;
}
Expand description

The SpawnAsync trait provides an interface for spawning asynchronous tasks on a runtime or executor.

This trait abstracts over asynchronous task execution environments (such as Tokio, smol, or a custom thread pool). It returns a handle implementing the Task trait.

§Examples

use node_flow::context::{SpawnAsync, Task};
use std::future::Future;

struct MyRuntime;
struct DummyTask<T>(T);
impl<T> Future for DummyTask<T> // ...
impl<T> Task<T> for DummyTask<T> // ...

impl SpawnAsync for MyRuntime {
    fn spawn<F>(fut: F) -> impl Task<F::Output>
    where
        F: Future + Send + 'static,
        F::Output: Send + 'static,
    {
        // Example stub (replace with actual runtime call)
        DummyTask(todo!())
    }
}

Required Methods§

Source

fn spawn<F>(fut: F) -> impl Task<F::Output>
where F: Future + Send + 'static, F::Output: Send + 'static,

Spawns an asynchronous concurrent task.

The task must be Send + 'static, as it may execute on another thread.

§Returns

A task handle implementing Task trait.

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§