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§
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.