1.0.0 • Published 6 years ago
buffer-async-iterator v1.0.0
buffer-async-iterator
Buffer an AsyncIterator before iteration.
Create an AsyncIterator over the values of an AsyncIterator, eagerly iterated.
Install
$ yarn buffer-async-iterator
API
Table of Contents
bufferAsyncIterator
Create an AsyncIterator from iterable
, with the values eagerly buffered.
Parameters
iterable
(AsyncIterable<Value> | Iterable<Value>) The iterable whose values will be buffered.write
Write A function that takesiterable
andbuffer
and returns a Promise.buffer
will not be iterated through until it resolves. (optional, defaultdefaultWrite
)buffer
(AsyncIterable<Value> | Iterable<Value>) An iterable representing the data being buffered. (optional, default[]
)
Examples
import bufferAsyncIterator from 'bufferAsyncIterator';
import got from 'got';
async function* getWebsites(sites) {
for (const site of sites) {
yield await got(site);
}
}
// Immediate start running the generator.
const websiteIterator = bufferAsyncIterator(getWebsites(['google.com', 'bing.com', 'is-yahoo-still-around.com']));
for await (const site of websiteIterator) {
// Iteration begins only after the original generator has finished.
}
License
MIT © Matthew Fernando Garcia
1.0.0
6 years ago