UNPKG

iter-tools-es

Version:
35 lines (29 loc) 840 B
const { asyncIterableCurry } = require('../../internal/async-iterable.js'); const { CircularBuffer, ReadOnlyCircularBuffer } = require('../../internal/circular-buffer.js'); async function* __asyncWindowBehind(source, size, { filler } = {}) { const buffer = new CircularBuffer(size); const bufferReadProxy = new ReadOnlyCircularBuffer(buffer); buffer.fill(filler); for await (const value of source) { buffer.push(value); yield bufferReadProxy; } } exports.__asyncWindowBehind = __asyncWindowBehind; const asyncWindowBehind = /*#__PURE__*/asyncIterableCurry(__asyncWindowBehind, { minArgs: 1, maxArgs: 2, validateArgs(args) { if (typeof args[1] !== 'number') { throw new Error(`${'asyncWindowBehind'} must be passed a numeric size`); } } }); exports.asyncWindowBehind = asyncWindowBehind;