77 releases

0.4.42 Mar 4, 2024
0.4.40 Jan 12, 2024
0.4.39 Nov 27, 2023
0.4.37 Jun 12, 2023
0.3.5 Nov 12, 2018

#1 in #converting

Download history 496888/week @ 2024-01-05 554220/week @ 2024-01-12 602505/week @ 2024-01-19 576874/week @ 2024-01-26 631932/week @ 2024-02-02 636308/week @ 2024-02-09 602610/week @ 2024-02-16 643332/week @ 2024-02-23 651886/week @ 2024-03-01 637560/week @ 2024-03-08 633286/week @ 2024-03-15 664207/week @ 2024-03-22 654441/week @ 2024-03-29 653683/week @ 2024-04-05 676366/week @ 2024-04-12 567023/week @ 2024-04-19

2,675,750 downloads per month
Used in 15,458 crates (699 directly)

MIT/Apache

2MB
40K SLoC

wasm-bindgen-futures

API Documentation

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.


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.7–1.3MB
~27K SLoC