2
0
Fork 0
mirror of https://github.com/leptos-rs/leptos synced 2025-02-03 07:23:26 +00:00
leptos/any_spawner
Greg Johnston ef72f1ce96 v0.7.1
2024-12-16 20:52:00 -05:00
..
src Makes the wasm32-wasip1/2 target a first-class citizen for Leptos's Server-Side () 2024-11-02 09:44:50 -07:00
tests Add support for user-supplied executors () 2024-10-16 06:24:07 -07:00
Cargo.toml v0.7.1 2024-12-16 20:52:00 -05:00
Makefile.toml chore(ci): add Makefiles for smaller packages 2024-08-01 19:42:21 -04:00
README.md prep for preview release 2024-08-01 19:40:56 -04:00

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 [Future]s.

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 { /* ... */ });