@reactivex/ix-esnext-esm
Version:
The Interactive Extensions for JavaScript
40 lines (38 loc) • 1.07 kB
JavaScript
import { AsyncIterableX } from '../asynciterablex';
export class BufferAsyncIterable extends AsyncIterableX {
constructor(source, count, skip) {
super();
this._source = source;
this._count = count;
this._skip = skip;
}
async *[Symbol.asyncIterator]() {
const buffers = [];
let i = 0;
for await (const item of this._source) {
if (i % this._skip === 0) {
buffers.push([]);
}
for (const buff of buffers) {
buff.push(item);
}
if (buffers.length > 0 && buffers[0].length === this._count) {
yield buffers.shift();
}
i++;
}
while (buffers.length > 0) {
yield buffers.shift();
}
}
}
export function buffer(count, skip) {
let s = skip;
if (s == null) {
s = count;
}
return function bufferOperatorFunction(source) {
return new BufferAsyncIterable(source, count, s);
};
}
//# sourceMappingURL=buffer.mjs.map