Module workflow_wasm::stream

source ·
Expand description

Conversion from Rust streams into async JavaScript generators.

This module allows you to convert any future::Stream<Item> where Item : Into<JsValue> into an async JavaScript generator.

let js_value : JsValue = AsyncStream::new(stream).into();

or

let js_value = create_async_stream_iterator(stream);

For example:

#[wasm_bindgen]
fn test() {
   let iter = stream::iter(0..30);
   AsyncStream::new(iter).into()
}

Then, on JavaScript side, you can can consume it as follows:

    let iter = myFn(); // get the generator from Rust
    for await (let item of iter) {
           console.log("item ->",item);
    }

Structs

  • AsyncStream is a helper that receives a stream that must correspond to the following spec: Stream<Item = T> where T : Into<JsValue> + Send + 'static. The stream must be supplied via the AsyncStream::new constructor.

Functions

  • Helper function that receives a stream and returns a JsValue representing the JavaScript generator iterating this stream. The function uses AsyncStream internally as follows: AsyncStream::new(stream).into()