@iam4x/bsc-scan
Version:
An efficient BNB and token balance scanner
16 lines • 999 B
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0}),exports.batch=exports.chunk=void 0;/**
* Split an array per `size` items.
*
* @param {T[]} input
* @param {number} size
* @return {T[][]} An array of arrays of the specified type.
* @template T
*/const chunk=(a,b)=>a.reduce((a,c,d)=>0==d%b?[...a,[c]]:[...a.slice(0,-1),[...a.slice(-1)[0],c]],[]);/**
* Batch the function calls to `handler` per `size` items.
*
* @param {(addresses: string[] | number[]) => Promise<BigNumber[]>} handler A function that takes a batch of addresses and returns the balance for the addresses.
* @param {number} size The size of the batches.
* @param {string[] | number[]} addresses The addresses to batch.
* @return {Promise<BigNumber[]>} A promise with the balances.
*/exports.chunk=chunk;const batch=async(a,b,c)=>{const d=chunk(c,b);return d.reduce(async(b,c)=>Promise.resolve([...(await b),...(await a(c))]),Promise.resolve([]))};exports.batch=batch;
//# sourceMappingURL=batch.js.map