5 ms·
Node.js Readable and Web API's ReadableStream both implement [Symbol.asyncIterator], which means you can usually use `for await` without extra code nowadays
by Jarred 3y ago
Node.js Readable and Web API's ReadableStream both implement [Symbol.asyncIterator], which means you can usually use `for await` without extra code nowadays
- explaininjs 3y agoFirefox is the only browser that implements it. For all the others you need this sort of machinery: async function* AsAsyncIterable<T>( readable: ReadableStream<T>, ): AsyncIterable<T> { const reader = readable.getReader() try { while (true) { const { done, value } = await reader.read() if (done) return yield value } } finally { reader.releaseLock() } }