Module runtime

Module runtime 

Source
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

TokioWASM Equivalent
tokio::spawnwasm_bindgen_futures::spawn_local
tokio::sync::mpscfutures_channel::mpsc
tokio::sync::oneshotfutures_channel::oneshot
tokio::time::timeoutManual with gloo-timers
tokio::time::sleepgloo_timers::future::sleep
tokio::sync::Mutexfutures_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§

AbortHandle
Handle that can be used to abort a spawned task.
Mutex
An asynchronous Mutex-like type.
OneshotReceiver
Receives a value from the associated Sender.
OneshotSender
Sends a value to the associated Receiver.
Receiver
Receives values from the associated Sender.
SendError
Error returned by Sender::send.
Sender
Sends values to the associated Receiver.
UnboundedReceiver
Receive values from the associated UnboundedSender.
UnboundedSender
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.