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

wasm-bindgen-futures

Bridging the gap between Rust Futures and JavaScript Promises

47 releases

✓ Uses Rust 2018 edition

0.4.12 May 1, 2020
0.4.10 Mar 26, 2020
0.4.6 Dec 20, 2019
0.4.5 Nov 19, 2019
0.3.5 Nov 12, 2018

#40 in WebAssembly

Download history 47335/week @ 2020-01-25 38158/week @ 2020-02-01 33134/week @ 2020-02-08 28023/week @ 2020-02-15 32008/week @ 2020-02-22 42853/week @ 2020-02-29 34643/week @ 2020-03-07 34832/week @ 2020-03-14 33800/week @ 2020-03-21 35118/week @ 2020-03-28 36590/week @ 2020-04-04 41402/week @ 2020-04-11 43278/week @ 2020-04-18 42927/week @ 2020-04-25 42495/week @ 2020-05-02 42561/week @ 2020-05-09

156,922 downloads per month
Used in 894 crates (74 directly)

MIT/Apache

2MB
35K 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

~0.8–1.2MB
~25K SLoC