#binding-generator #futures #bindgen #javascript


Bridging the gap between Rust Futures and JavaScript Promises

65 releases

0.4.30 Apr 7, 2022
0.4.29 Jan 19, 2022
0.4.28 Sep 15, 2021
0.4.24 May 10, 2021
0.3.5 Nov 12, 2018

#668 in WebAssembly

Download history 151675/week @ 2022-02-05 155111/week @ 2022-02-12 163912/week @ 2022-02-19 226396/week @ 2022-02-26 200189/week @ 2022-03-05 189726/week @ 2022-03-12 183497/week @ 2022-03-19 176090/week @ 2022-03-26 190194/week @ 2022-04-02 184786/week @ 2022-04-09 176311/week @ 2022-04-16 169417/week @ 2022-04-23 156641/week @ 2022-04-30 180611/week @ 2022-05-07 174987/week @ 2022-05-14 168718/week @ 2022-05-21

707,309 downloads per month
Used in 5,835 crates (289 directly)


38K SLoC


API Documention

This crate bridges the gap between a Rust Future and a JavaScript Promise. It provides two conversions:

  1. From a JavaScript Promise into a Rust Future.
  2. From a Rust Future into a JavaScript Promise.

Additionally under the feature flag futures-core-03-stream there is experimental support for AsyncIterator to Stream conversion.

See the API documentation for more info.


Converting between JavaScript Promises to Rust Futures.

This crate provides a bridge for working with JavaScript Promise types as a Rust Future, and similarly contains utilities to turn a rust Future into a JavaScript Promise. This can be useful when working with asynchronous or otherwise blocking work in Rust (wasm), and provides the ability to interoperate with JavaScript events and JavaScript I/O primitives.

There are three main interfaces in this crate currently:

  1. JsFuture

    A type that is constructed with a Promise and can then be used as a Future<Output = Result<JsValue, JsValue>>. This Rust future will resolve or reject with the value coming out of the Promise.

  2. future_to_promise

    Converts a Rust Future<Output = Result<JsValue, JsValue>> into a JavaScript Promise. The future's result will translate to either a resolved or rejected Promise in JavaScript.

  3. spawn_local

    Spawns a Future<Output = ()> on the current thread. This is the best way to run a Future in Rust without sending it to JavaScript.

These three items should provide enough of a bridge to interoperate the two systems and make sure that Rust/JavaScript can work together with asynchronous and I/O work.


~24K SLoC