Skip to content

Creating a readable stream from async iterables #8808

Answered by danopia
ducaale asked this question in Q&A
Discussion options

You must be logged in to vote

Perhaps this std import/function readableStreamFromAsyncIterator answers your original question: https://deno.land/[email protected]/io/streams.ts#L50

async function* ids() {
  for (let i = 0; i < 10; i++) {
    yield i;
  }
}

// Create a stream
import {readableStreamFromAsyncIterator} from "https://deno.land/[email protected]/io/streams.ts";
const idStream = readableStreamFromAsyncIterator(ids());

// Consume the stream
import {collect} from "https://uber.danopia.net/deno/observables-with-streams@v1/sinks/collect.ts";
console.log('All IDs:', await collect(idStream));

As long as you're talking about async iterables, that is. If your iterable isn't async then std doesn't have an implementation. The non…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by ducaale
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants