Expand description
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
ⓘ
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;Structs§
- Abort
Handle - Handle that can be used to abort a spawned task.
- Mutex
- An asynchronous
Mutex-like type. - Oneshot
Receiver - Receives a value from the associated
Sender. - Oneshot
Sender - Sends a value to the associated
Receiver. - Receiver
- Receives values from the associated
Sender. - Send
Error - Error returned by
Sender::send. - Sender
- Sends values to the associated
Receiver. - Unbounded
Receiver - Receive values from the associated
UnboundedSender. - Unbounded
Sender - Send values to the associated
UnboundedReceiver.
Functions§
- bounded
- Create a bounded mpsc channel.
- channel
- Creates a bounded mpsc channel for communicating between asynchronous tasks with backpressure.
- oneshot
- Create a oneshot channel.
- sleep
- Sleep for the given duration.
- spawn
- Spawn a task that runs concurrently.
- spawn_
with_ abort - Spawn a task and return an abort handle that can be used to cancel it.
- timeout
- Run a future with a timeout.
- unbounded
- Create an unbounded mpsc channel.
- unbounded_
channel - Creates an unbounded mpsc channel for communicating between asynchronous tasks without backpressure.