UNPKG

alinea

Version:

[![npm](https://img.shields.io/npm/v/alinea.svg)](https://npmjs.org/package/alinea) [![install size](https://packagephobia.com/badge?p=alinea)](https://packagephobia.com/result?p=alinea)

54 lines (52 loc) 1.11 kB
import "../../chunks/chunk-U5RRZUYZ.js"; // src/cli/util/Emitter.ts var Emitter; ((Emitter2) => { Emitter2.CANCELLED = "EMIT_CANCELLED"; })(Emitter || (Emitter = {})); function createEmitter() { const queue = []; let resolve; const push = (p) => { queue.push(p); if (resolve) { resolve(); resolve = void 0; } }; const iterator = { async next() { while (!queue.length) { await new Promise((_) => resolve = _); } const current = queue.pop(); switch (current.type) { case "emit": return { value: current.value, done: false }; case "error": throw current.value; case "finish": return { value: void 0, done: true }; } } }; return { emit: (value) => push({ type: "emit", value }), throw(e) { push({ type: "error", value: e }); }, cancel() { this.throw(Emitter.CANCELLED); }, return() { queue.push({ type: "finish" }); }, [Symbol.asyncIterator]() { return iterator; } }; } export { Emitter, createEmitter };