Crate of the Week

output

Self-suggestion: I'd like to humbly suggest tokio_with_wasm, a crate that lets a single tokio codebase run both natively and in web browsers.

It has already reached 1.7 million downloads on crates.io.

use tokio_with_wasm::alias as tokio;
use std::time::Duration;

let async_handle = tokio::task::spawn(async { fetch_data().await });
let blocking_handle = tokio::task::spawn_blocking(|| heavy_work());
tokio::time::sleep(Duration::from_secs(1)).await;

On native targets, the alias simply resolves to real tokio. On wasm32-unknown-unknown, it provides the same API on top of JavaScript web APIs — spawn_blocking runs on an auto-scaling pool of Web Workers. We hope it's useful for anyone bringing async Rust to the web!