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