Skip to content

Commit c789ee7

Browse files
committed
Add stream feature to futures crate
1 parent df98dbe commit c789ee7

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

crates/futures/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ edition = "2018"
1414
cfg-if = "1.0.0"
1515
js-sys = { path = "../js-sys", version = '0.3.46' }
1616
wasm-bindgen = { path = "../..", version = '0.2.69' }
17-
futures-core = { version = '0.3.8', default-features = false }
17+
futures-core = { version = '0.3.8', default-features = false, optional = true }
18+
19+
[features]
20+
stream = ['futures-core']
1821

1922
[target.'cfg(target_feature = "atomics")'.dependencies.web-sys]
2023
path = "../web-sys"

crates/futures/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
[API Documention][docs]
44

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

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

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

crates/futures/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ use std::task::{Context, Poll, Waker};
4343
use wasm_bindgen::prelude::*;
4444

4545
mod queue;
46+
#[cfg(feature = "stream")]
4647
pub mod stream;
4748

4849
mod task {

crates/futures/tests/tests.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
44

55
use futures_channel::oneshot;
6-
use wasm_bindgen::{prelude::*, JsCast};
7-
use wasm_bindgen_futures::{future_to_promise, spawn_local, stream::JsStream, JsFuture};
6+
use wasm_bindgen::prelude::*;
7+
use wasm_bindgen_futures::{future_to_promise, spawn_local, JsFuture};
88
use wasm_bindgen_test::*;
99

1010
#[wasm_bindgen_test]
@@ -89,9 +89,13 @@ async fn can_create_multiple_futures_from_same_promise() {
8989
b.await.unwrap();
9090
}
9191

92+
#[cfg(feature = "stream")]
9293
#[wasm_bindgen_test]
9394
async fn can_use_an_async_iterable_as_stream() {
9495
use futures_lite::stream::StreamExt;
96+
use wasm_bindgen::JsCast;
97+
use wasm_bindgen_futures::stream::JsStream;
98+
9599
let async_iter = js_sys::Function::new_no_args(
96100
"return async function*() {
97101
yield 42;

0 commit comments

Comments
 (0)