roam_session/runtime/
mod.rs

1//! Runtime abstraction layer for tokio/WASM portability.
2//!
3//! This module provides abstractions over async runtime primitives so the same
4//! code can run on both tokio (native) and WASM runtimes.
5//!
6//! # Supported Primitives
7//!
8//! | Tokio              | WASM Equivalent              |
9//! |--------------------|------------------------------|
10//! | `tokio::spawn`     | `wasm_bindgen_futures::spawn_local` |
11//! | `tokio::sync::mpsc`| `futures_channel::mpsc`      |
12//! | `tokio::sync::oneshot` | `futures_channel::oneshot` |
13//! | `tokio::time::timeout` | Manual with gloo-timers  |
14//! | `tokio::time::sleep` | `gloo_timers::future::sleep` |
15//! | `tokio::sync::Mutex` | `futures_util::lock::Mutex`  |
16//!
17//! # Usage
18//!
19//! ```ignore
20//! use roam_session::runtime;
21//!
22//! // Spawn a task
23//! runtime::spawn(async { /* ... */ });
24//!
25//! // Create channels
26//! let (tx, rx) = runtime::channel(16);
27//! let (otx, orx) = runtime::oneshot();
28//!
29//! // Timeouts and sleeping
30//! runtime::sleep(Duration::from_secs(1)).await;
31//! let result = runtime::timeout(Duration::from_secs(5), some_future).await;
32//! ```
33
34#[cfg(not(target_arch = "wasm32"))]
35mod tokio_runtime;
36#[cfg(not(target_arch = "wasm32"))]
37pub use tokio_runtime::*;
38
39#[cfg(target_arch = "wasm32")]
40mod wasm;
41#[cfg(target_arch = "wasm32")]
42pub use wasm::*;