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 implement
SpawnCustom - Layered: Compose middleware closures via
CustomSpawnerBuilder - 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);§Thread-Aware Support
Spawner implements ThreadAware and supports
per-core isolation via custom SpawnCustom implementations, enabling
contention-free, NUMA-friendly task dispatch.
§Features
tokio: Enables theSpawner::new_tokioandSpawner::new_tokio_with_handleconstructors
Structs§
- Custom
Spawner Builder - Builds a
Spawnerfrom a base spawner plus zero or more layers. - Join
Handle - A handle to a spawned task that can be awaited to retrieve its result.
- Spawner
- Runtime-agnostic task spawner.
Traits§
- Spawn
Custom - Trait for implementing custom task spawners.
- Thread
Aware Async FnOnce - Async equivalent of
ThreadAwareFnOnce- calls the closure once, returning aBoxFuture.
Type Aliases§
- Boxed
Blocking Task - A type-erased, heap-allocated synchronous closure that returns
(). - Boxed
Future - A type-erased, heap-allocated, pinned future that returns
().