80 releases
0.4.45 | Oct 10, 2024 |
---|---|
0.4.43 | Aug 12, 2024 |
0.4.42 | Mar 4, 2024 |
0.4.39 | Nov 27, 2023 |
0.3.5 | Nov 12, 2018 |
#81 in Asynchronous
3,988,027 downloads per month
Used in 18,902 crates
(841 directly)
2.5MB
43K
SLoC
wasm-bindgen-futures
This crate bridges the gap between a Rust Future
and a JavaScript
Promise
. It provides two conversions:
- From a JavaScript
Promise
into a RustFuture
. - From a Rust
Future
into a JavaScriptPromise
.
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 Promise
s to Rust Future
s.
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:
-
A type that is constructed with a
Promise
and can then be used as aFuture<Output = Result<JsValue, JsValue>>
. This Rust future will resolve or reject with the value coming out of thePromise
. -
Converts a Rust
Future<Output = Result<JsValue, JsValue>>
into a JavaScriptPromise
. The future's result will translate to either a resolved or rejectedPromise
in JavaScript. -
Spawns a
Future<Output = ()>
on the current thread. This is the best way to run aFuture
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.6–1.2MB
~24K SLoC