From 1ed7c52b29e15057f31d8146c0ec9fd8b5d26308 Mon Sep 17 00:00:00 2001 From: Daniel Olano Date: Mon, 4 Jan 2021 18:34:49 +0100 Subject: [PATCH] Add stream feature to futures crate --- crates/futures/Cargo.toml | 5 ++++- crates/futures/README.md | 3 +++ crates/futures/src/lib.rs | 1 + crates/futures/tests/tests.rs | 8 ++++++-- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/crates/futures/Cargo.toml b/crates/futures/Cargo.toml index 28b1cd1d253d..641a96c6800a 100644 --- a/crates/futures/Cargo.toml +++ b/crates/futures/Cargo.toml @@ -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" diff --git a/crates/futures/README.md b/crates/futures/README.md index 9f6518fef81d..0c0bffe7a213 100644 --- a/crates/futures/README.md +++ b/crates/futures/README.md @@ -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/ diff --git a/crates/futures/src/lib.rs b/crates/futures/src/lib.rs index 26ee20dc9c24..03eb0f2682f1 100644 --- a/crates/futures/src/lib.rs +++ b/crates/futures/src/lib.rs @@ -43,6 +43,7 @@ use std::task::{Context, Poll, Waker}; use wasm_bindgen::prelude::*; mod queue; +#[cfg(feature = "stream")] pub mod stream; mod task { diff --git a/crates/futures/tests/tests.rs b/crates/futures/tests/tests.rs index ad95736722fe..a400e003412e 100644 --- a/crates/futures/tests/tests.rs +++ b/crates/futures/tests/tests.rs @@ -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] @@ -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;