#futures #bindgen #gap #future #bridges #promises #conversions

wasm-bindgen-futures

Bridging the gap between Rust Futures and JavaScript Promises

39 releases

✓ Uses Rust 2018 edition

new 0.4.4 Nov 7, 2019
0.4.1 Sep 26, 2019
0.3.25 Jul 11, 2019
0.3.17 Mar 22, 2019
0.3.5 Nov 12, 2018

#12 in WebAssembly

Download history 2392/week @ 2019-07-25 2604/week @ 2019-08-01 3417/week @ 2019-08-08 5055/week @ 2019-08-15 5145/week @ 2019-08-22 7105/week @ 2019-08-29 9204/week @ 2019-09-05 9320/week @ 2019-09-12 10854/week @ 2019-09-19 11285/week @ 2019-09-26 12063/week @ 2019-10-03 12337/week @ 2019-10-10 12727/week @ 2019-10-17 15081/week @ 2019-10-24 14781/week @ 2019-10-31

43,259 downloads per month
Used in 135 crates (40 directly)

MIT/Apache

455KB
4.5K SLoC

wasm-bindgen-futures

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.

See the API documentation for more info.


lib.rs:

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.

Dependencies

~1–1.3MB
~29K SLoC