Skip to content

Commit a77f780

Browse files
test(jco): enable nested stream test
1 parent 819837a commit a77f780

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

crates/test-components/src/bin/stream_tx.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,20 @@ impl get_stream_async::Guest for Component {
204204
});
205205
Ok(rx)
206206
}
207+
208+
async fn get_stream_stream_string(
209+
vals: Vec<String>,
210+
) -> Result<StreamReader<StreamReader<String>>, String> {
211+
let (mut tx, rx) = wit_stream::new();
212+
wit_bindgen::spawn(async move {
213+
for v in vals {
214+
let (mut nested_tx, nested_rx) = wit_stream::new();
215+
tx.write(vec![nested_rx]).await;
216+
nested_tx.write(vec![v]).await;
217+
}
218+
});
219+
Ok(rx)
220+
}
207221
}
208222

209223
fn stream_values_async<T: StreamPayload>(vals: Vec<T>) -> Result<StreamReader<T>, String> {

crates/test-components/wit/all.wit

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ interface get-stream-async {
110110

111111
get-stream-example-resource-own-attr: async func(vals: list<example-resource>) -> result<stream<u32>, string>;
112112

113-
//get-stream-stream-string: async func(vals: list<stream<string>>) -> result<stream<stream<string>>, string>;
113+
get-stream-stream-string: async func(vals: list<string>) -> result<stream<stream<string>>, string>;
114+
114115
//get-stream-future-string: async func(vals: list<future<string>>) -> result<stream<future<string>>, string>;
115116
}
116117

packages/jco/test/p3/stream.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,16 @@ suite("stream<T> lifts", () => {
345345
expectedValues: [2, 1, 0],
346346
});
347347
});
348+
349+
test("stream<string>", async () => {
350+
assert.instanceOf(instance["jco:test-components/get-stream-async"].getStreamStreamString, AsyncFunction);
351+
let vals = ["first", "third", "second"];
352+
let stream = await instance["jco:test-components/get-stream-async"].getStreamStreamString(vals);
353+
for (const v of vals) {
354+
const nestedStream = await stream.next();
355+
assert.strictEqual(v, await nestedStream.next());
356+
}
357+
});
348358
});
349359

350360
async function checkStreamValues(args) {

0 commit comments

Comments
 (0)