1.0.0 • Published 7 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-iteratorAPI
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.writeWrite A function that takesiterableandbufferand returns a Promise.bufferwill 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
7 years ago