Skip to main content

teksilo_async_std/
lib.rs

1// SPDX-License-Identifier: MPL-2.0
2// SPDX-FileCopyrightText: 2026 FernTech
3
4//! # teksilo-async-std — async-std reactor for Teksilo's async executor
5//!
6//! Thin adapter over [`teksilo-async`](teksilo_async). Unlike Tokio, async-std
7//! runs a **global** reactor that starts lazily on first use, so no per-tick
8//! runtime-context guard is needed: `install_async_async_std()` is exactly
9//! [`install_async`](teksilo_async::TeksiloAppBuilderAsyncExt::install_async)
10//! plus the async-std dependency in the tree. Native async-std futures
11//! (`async_std::task::sleep`, async-std sockets, …) can be `.await`ed directly
12//! inside `ctx.spawn_local(...)` bodies — when a leaf future is ready, the
13//! global reactor wakes the executor's `Waker` and the loop ticks again.
14//!
15//! ```ignore
16//! use teksilo_async_std::TeksiloAppBuilderAsyncStdExt;
17//! TeksiloAppBuilder::new().install_async_async_std() /* ... */ .run();
18//!
19//! ctx.spawn_local(async move {
20//!     async_std::task::sleep(std::time::Duration::from_secs(1)).await;
21//!     status.set("done".into());
22//! })
23//! .detach();
24//! ```
25
26use teksilo_app::TeksiloAppBuilder;
27use teksilo_async::TeksiloAppBuilderAsyncExt;
28
29// Re-export the spawn surface so `use teksilo_async_std::*;` is enough for
30// crate users that don't go through the `teksilo` umbrella prelude.
31pub use teksilo_async::{EventContextAsyncExt, TaskHandle, spawn_blocking};
32
33/// Adds [`install_async_async_std`](TeksiloAppBuilderAsyncStdExt::install_async_async_std)
34/// to the app builder.
35pub trait TeksiloAppBuilderAsyncStdExt {
36    /// Install the main-thread executor for use with async-std futures. Since
37    /// async-std's reactor is global and auto-starting, this is `install_async`
38    /// — the value of this crate is pulling async-std into the dependency tree
39    /// and providing a discoverable, parallel entry point to `teksilo-tokio`.
40    fn install_async_async_std(self) -> Self;
41}
42
43impl TeksiloAppBuilderAsyncStdExt for TeksiloAppBuilder {
44    fn install_async_async_std(self) -> Self {
45        self.install_async()
46    }
47}