Back to Wasm Bindgen

`wasm-bindgen-futures`

crates/futures/README.md

0.2.1201.5 KB
Original Source

wasm-bindgen-futures

API Documentation

This crate bridges the gap between Rust Futures and JavaScript Promises.

As of this version the implementation lives in js-sys under the futures feature. Depending on this crate automatically activates that feature, which gives js_sys::Promise a first-class IntoFuture implementation — meaning you can .await any Promise directly:

rust
use js_sys::Promise;
use wasm_bindgen::prelude::*;

async fn example(promise: Promise) -> Result<JsValue, JsValue> {
    promise.await
}

All public items from the previous API are re-exported unchanged for backwards compatibility:

Under the feature flag futures-core-03-stream there is support for AsyncIterator to Stream conversion via JsStream.

See the API documentation for more info.