UNPKG

1.61 kBSource Map (JSON)View Raw
1{"version":3,"sources":["asynciterable/interval.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,MAAM,qBAAsB,SAAQ,cAAsB;IAGxD,YAAY,OAAe;QACzB,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,MAAoB;QAChD,cAAc,CAAC,MAAM,CAAC,CAAC;QACvB,IAAI,CAAC,GAAG,CAAC,CAAC;QACV,OAAO,CAAC,EAAE;YACR,MAAM,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;YACnC,MAAM,CAAC,EAAE,CAAC;SACX;IACH,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAAM,UAAU,QAAQ,CAAC,OAAe;IACtC,OAAO,IAAI,qBAAqB,CAAC,OAAO,CAAC,CAAC;AAC5C,CAAC","file":"interval.js","sourcesContent":["import { AsyncIterableX } from './asynciterablex';\nimport { sleep } from './_sleep';\nimport { throwIfAborted } from '../aborterror';\n\nclass IntervalAsyncIterable extends AsyncIterableX<number> {\n private _dueTime: number;\n\n constructor(dueTime: number) {\n super();\n this._dueTime = dueTime;\n }\n\n async *[Symbol.asyncIterator](signal?: AbortSignal) {\n throwIfAborted(signal);\n let i = 0;\n while (1) {\n await sleep(this._dueTime, signal);\n yield i++;\n }\n }\n}\n\n/**\n * Produces a new item in an async-iterable at the given interval cycle time.\n *\n * @export\n * @param {number} dueTime The due time in milliseconds to spawn a new item.\n * @returns {AsyncIterableX<number>} An async-iterable producing values at the specified interval.\n */\nexport function interval(dueTime: number): AsyncIterableX<number> {\n return new IntervalAsyncIterable(dueTime);\n}\n"]}
\No newline at end of file