UNPKG

@daiso-tech/core

Version:

The library offers flexible, framework-agnostic solutions for modern web applications, built on adaptable components that integrate seamlessly with popular frameworks like Next Js.

39 lines 1.18 kB
/** * @module Collection */ import {} from "../../../../collection/contracts/_module-exports.js"; import {} from "../../../../utilities/_module-exports.js"; /** * @internal */ export class AsyncChunkIterable { collection; chunkSize; makeCollection; constructor(collection, chunkSize, makeCollection) { this.collection = collection; this.chunkSize = chunkSize; this.makeCollection = makeCollection; } async *[Symbol.asyncIterator]() { const array = []; let currentChunkSize = 0; let isFirstIteration = true; for await (const item of this.collection) { currentChunkSize %= this.chunkSize; const isFilled = currentChunkSize === 0; if (!isFirstIteration && isFilled) { yield this.makeCollection(array); array.length = 0; } array.push(item); currentChunkSize++; isFirstIteration = false; } const hasRest = currentChunkSize !== 0; if (hasRest) { yield this.makeCollection(array); } } } //# sourceMappingURL=async-chunk-iterable.js.map