Skip to content

Commit

Permalink
Add stream feature to futures crate
Browse files Browse the repository at this point in the history
  • Loading branch information
olanod committed Jan 4, 2021
1 parent df98dbe commit c789ee7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
5 changes: 4 additions & 1 deletion crates/futures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ edition = "2018"
cfg-if = "1.0.0"
js-sys = { path = "../js-sys", version = '0.3.46' }
wasm-bindgen = { path = "../..", version = '0.2.69' }
futures-core = { version = '0.3.8', default-features = false }
futures-core = { version = '0.3.8', default-features = false, optional = true }

[features]
stream = ['futures-core']

[target.'cfg(target_feature = "atomics")'.dependencies.web-sys]
path = "../web-sys"
Expand Down
3 changes: 2 additions & 1 deletion crates/futures/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
[API Documention][docs]

This crate bridges the gap between a Rust `Future` and a JavaScript
`Promise`. It provides two conversions:
`Promise`. It provides three conversions:

1. From a JavaScript `Promise` into a Rust `Future`.
2. From a Rust `Future` into a JavaScript `Promise`.
3. From a JavaScript `AsyncIterator` into a Rust `Stream`(behind the `stream` flag).

See the [API documentation][docs] for more info.

Expand Down
1 change: 1 addition & 0 deletions crates/futures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ use std::task::{Context, Poll, Waker};
use wasm_bindgen::prelude::*;

mod queue;
#[cfg(feature = "stream")]
pub mod stream;

mod task {
Expand Down
8 changes: 6 additions & 2 deletions crates/futures/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);

use futures_channel::oneshot;
use wasm_bindgen::{prelude::*, JsCast};
use wasm_bindgen_futures::{future_to_promise, spawn_local, stream::JsStream, JsFuture};
use wasm_bindgen::prelude::*;
use wasm_bindgen_futures::{future_to_promise, spawn_local, JsFuture};
use wasm_bindgen_test::*;

#[wasm_bindgen_test]
Expand Down Expand Up @@ -89,9 +89,13 @@ async fn can_create_multiple_futures_from_same_promise() {
b.await.unwrap();
}

#[cfg(feature = "stream")]
#[wasm_bindgen_test]
async fn can_use_an_async_iterable_as_stream() {
use futures_lite::stream::StreamExt;
use wasm_bindgen::JsCast;
use wasm_bindgen_futures::stream::JsStream;

let async_iter = js_sys::Function::new_no_args(
"return async function*() {
yield 42;
Expand Down

0 comments on commit c789ee7

Please sign in to comment.