Expand description
A generic task spawner compatible with any async runtime.
This crate provides a Spawner type that abstracts task spawning across
different async runtimes without generic infection.
§Design Philosophy
- Concrete type: No generics needed in your code
- Simple: Use built-in constructors or provide a closure
- Flexible: Works with any async runtime
§Quick Start
§Using Tokio
use anyspawn::Spawner;
let spawner = Spawner::new_tokio();
let result = spawner.spawn(async { 1 + 1 }).await;
assert_eq!(result, 2);§Custom Runtime
ⓘ
use anyspawn::Spawner;
let spawner = Spawner::new_custom("threadpool", |fut| {
std::thread::spawn(move || futures::executor::block_on(fut));
});
// Returns a JoinHandle that can be awaited or dropped
let handle = spawner.spawn(async { 42 });§Features
tokio(default): Enables theSpawner::new_tokioconstructorcustom: EnablesSpawner::new_customandCustomSpawnerBuilder
Structs§
- Custom
Spawner Builder custom - A typestate builder for constructing a
Spawnerwith layered future transformations. - Join
Handle tokioorcustom - A handle to a spawned task that can be awaited to retrieve its result.
- Spawner
tokioorcustom - Runtime-agnostic task spawner.
Type Aliases§
- Boxed
Future custom - A type-erased, heap-allocated, pinned future that returns
().