2018-08-08 17:41:36 -07:00
|
|
|
//! Converting between JavaScript `Promise`s to Rust `Future`s.
|
2018-08-01 15:52:24 -05:00
|
|
|
//!
|
2018-08-08 17:41:36 -07:00
|
|
|
//! 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.
|
2018-08-01 15:52:24 -05:00
|
|
|
//!
|
|
|
|
//! There are two main interfaces in this crate currently:
|
|
|
|
//!
|
2018-08-08 17:41:36 -07:00
|
|
|
//! 1. [**`JsFuture`**](./struct.JsFuture.html)
|
2018-08-01 15:52:24 -05:00
|
|
|
//!
|
2018-08-08 17:41:36 -07:00
|
|
|
//! A type that is constructed with a `Promise` and can then be used as a
|
|
|
|
//! `Future<Item = JsValue, Error = JsValue>`. This Rust future will resolve
|
|
|
|
//! or reject with the value coming out of the `Promise`.
|
|
|
|
//!
|
|
|
|
//! 2. [**`future_to_promise`**](./fn.future_to_promise.html)
|
|
|
|
//!
|
|
|
|
//! Converts a Rust `Future<Item = JsValue, Error = JsValue>` into a
|
|
|
|
//! JavaScript `Promise`. The future's result will translate to either a
|
|
|
|
//! rejected or resolved `Promise` in JavaScript.
|
|
|
|
//!
|
|
|
|
//! These two 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.
|
|
|
|
//!
|
|
|
|
//! # Example Usage
|
|
|
|
//!
|
|
|
|
//! This example wraps JavaScript's `Promise.resolve()` into a Rust `Future` for
|
|
|
|
//! running tasks on the next tick of the micro task queue. The futures built on
|
|
|
|
//! top of it can be scheduled for execution by conversion into a JavaScript
|
|
|
|
//! `Promise`.
|
2018-08-01 15:52:24 -05:00
|
|
|
|
2019-06-27 00:06:43 +03:00
|
|
|
#![cfg_attr(target_feature = "atomics", feature(stdsimd))]
|
2018-08-01 15:52:24 -05:00
|
|
|
#![deny(missing_docs)]
|
|
|
|
|
2019-06-27 00:06:43 +03:00
|
|
|
use cfg_if::cfg_if;
|
2018-08-01 15:52:24 -05:00
|
|
|
|
2019-09-05 11:18:36 -05:00
|
|
|
mod shared;
|
|
|
|
pub use shared::*;
|
2019-07-18 13:59:14 -07:00
|
|
|
|
2019-06-27 00:06:43 +03:00
|
|
|
cfg_if! {
|
|
|
|
if #[cfg(target_feature = "atomics")] {
|
2019-07-18 14:00:45 -07:00
|
|
|
mod wait_async_polyfill;
|
2019-09-05 11:18:36 -05:00
|
|
|
mod multithread;
|
|
|
|
pub use multithread::*;
|
2019-07-18 10:13:05 -07:00
|
|
|
} else {
|
2019-09-05 11:18:36 -05:00
|
|
|
mod singlethread;
|
|
|
|
pub use singlethread::*;
|
2019-06-27 00:06:43 +03:00
|
|
|
}
|
2019-05-04 09:17:29 +02:00
|
|
|
}
|