UNPKG

alinea

Version:
42 lines (40 loc) 831 B
import "../../chunks/chunk-NZLE2WMY.js"; // src/core/util/Async.ts async function accumulate(gen) { const acc = []; for await (const item of gen) acc.push(item); return acc; } async function* toGenerator(iterable) { for (const item of iterable) yield item; } function genEffect(gen, effect) { return { [Symbol.asyncIterator]() { const iter = gen[Symbol.asyncIterator](); const stack = []; const dispense = () => { stack.push( iter.next().then((res) => { if (!res.done) { effect(res.value); dispense(); } return res; }) ); }; dispense(); return { next() { return stack.shift(); } }; } }; } export { accumulate, genEffect, toGenerator };