创建一个带有输入和结束值的方法的同步执行器
这是最强大的功能之一,可以随意使用.
安装
> npm i @async-generator/subject
使用量
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
}