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 5, 2021
1 parent 52b5b10 commit 1ed7c52
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 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: 3 additions & 0 deletions crates/futures/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ This crate bridges the gap between a Rust `Future` and a JavaScript
1. From a JavaScript `Promise` into a Rust `Future`.
2. From a Rust `Future` into a JavaScript `Promise`.

Additionally under the feature flag `stream` there is experimental
support for `AsyncIterator` to `Stream` conversion.

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

[docs]: https://rustwasm.github.io/wasm-bindgen/api/wasm_bindgen_futures/
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 1ed7c52

Please sign in to comment.