lazy.js icon indicating copy to clipboard operation
lazy.js copied to clipboard

Support for native asynchronous generators

Open ghost opened this issue 5 years ago • 1 comments

async function* iterateDir(dir) {
    let list = await fs.readdir(dir); // fs-promise implementation of readdir
    for (let file of list) {
        yield file;
    }
}

Lazy.generate(iterateDir('./out'))
  .async(1000) // specifies a 1-second interval between each element
  .map(function(x) { return String.fromCharCode(x + 65); })
  .take(26)
  .each(function(char) { console.log(char); });

ghost avatar Sep 28 '18 04:09 ghost

I think generators are super suitable to be used with lazy.js . Hope this is going to be implemented! :)

yxliang01 avatar Feb 28 '19 13:02 yxliang01