6 releases

new 0.3.0-rc1 Apr 11, 2025
0.2.0 Nov 30, 2024
0.1.1 Jun 28, 2024
0.1.0 Apr 27, 2024

#243 in WebAssembly

Download history 2648/week @ 2024-12-22 3112/week @ 2024-12-29 4403/week @ 2025-01-05 5148/week @ 2025-01-12 5103/week @ 2025-01-19 4638/week @ 2025-01-26 5259/week @ 2025-02-02 6060/week @ 2025-02-09 6146/week @ 2025-02-16 6951/week @ 2025-02-23 6779/week @ 2025-03-02 7008/week @ 2025-03-09 7135/week @ 2025-03-16 7459/week @ 2025-03-23 5912/week @ 2025-03-30 6724/week @ 2025-04-06

27,798 downloads per month
Used in 96 crates (13 directly)

MIT license

25KB
334 lines

This crate makes it easier to write asynchronous code that is executor-agnostic, by providing a utility that can be used to spawn tasks in a variety of executors.

It only supports single executor per program, but that executor can be set at runtime, anywhere in your crate (or an application that depends on it).

This can be extended to support any executor or runtime that supports spawning Futures.

This is a least common denominator implementation in many ways. Limitations include:

  • setting an executor is a one-time, global action
  • no "join handle" or other result is returned from the spawn
  • the Future must output ()
use any_spawner::Executor;

// make sure an Executor has been initialized with one of the init_ functions

// spawn a thread-safe Future
Executor::spawn(async { /* ... */ });

// spawn a Future that is !Send
Executor::spawn_local(async { /* ... */ });

This crate makes it easier to write asynchronous code that is executor-agnostic, by providing a utility that can be used to spawn tasks in a variety of executors.

It only supports single executor per program, but that executor can be set at runtime, anywhere in your crate (or an application that depends on it).

This can be extended to support any executor or runtime that supports spawning Futures.

This is a least common denominator implementation in many ways. Limitations include:

  • setting an executor is a one-time, global action
  • no "join handle" or other result is returned from the spawn
  • the Future must output ()
use any_spawner::Executor;

Executor::init_futures_executor()
    .expect("executor should only be initialized once");

// spawn a thread-safe Future
Executor::spawn(async { /* ... */ });

// spawn a Future that is !Send
Executor::spawn_local(async { /* ... */ });

Dependencies

~0.9–9.5MB
~98K SLoC