Skip to main content

Crate anyspawn

Crate anyspawn 

Source
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

Structs§

CustomSpawnerBuilder
Builds a Spawner from a base spawner plus zero or more layers.
JoinHandle
A handle to a spawned task that can be awaited to retrieve its result.
Spawner
Runtime-agnostic task spawner.

Traits§

SpawnCustom
Trait for implementing custom task spawners.
ThreadAwareAsyncFnOnce
Async equivalent of ThreadAwareFnOnce - calls the closure once, returning a BoxFuture.

Type Aliases§

BoxedBlockingTask
A type-erased, heap-allocated synchronous closure that returns ().
BoxedFuture
A type-erased, heap-allocated, pinned future that returns ().