Miss any of our Open RFC calls?Watch the recordings here! »

@async-generator/subject

1.0.2 • Public • Published

create an async iterator with a method to feed values into and end it

This is one of the most powerful functions, use it sparely.

installation

> npm i @async-generator/subject

usage

const subject = require("@async-generator/subject");
 
const [iterator, feed, end] = subject();
 
sleep(100).then(async () => {
  feed(1);
  await sleep(100);
  feed(2);
 
  await sleep(100);
  feed(3);
 
  await sleep(100);
  feed(4);
 
  end();
});
 
for await (const item of iterator) {
  console.log(item); // will log 1, 2, 3, 4 and end loop afterward
}
 

Install

npm i @async-generator/subject

DownloadsWeekly Downloads

6

Version

1.0.2

License

MIT

Unpacked Size

3.09 kB

Total Files

5

Last publish

Collaborators

  • avatar