UNPKG

@hirosystems/api-toolkit

Version:
28 lines (27 loc) 1.34 kB
/** * Iterate over an array, yielding multiple items at a time. If the size of the given array * is not divisible by the given batch size, then the length of the last items returned will * be smaller than the given batch size, i.e.: * ```typescript * items.length % batchSize * ``` * @param items - The array to iterate over. * @param batchSize - Maximum number of items to return at a time. * @param printBenchmark - If we should print benchmark of items per second */ export declare function batchIterate<T>(items: T[], batchSize: number, printBenchmark?: boolean): Generator<T[]>; /** * Iterate over an `AsyncIterable`, yielding multiple items at a time. If the size of the given * array is not divisible by the given batch size, then the length of the last items returned will * be smaller than the given batch size. * * @param items - AsyncIterable * @param batchSize - Batch size * @param printBenchmark - If we should print benchmark of items per second */ export declare function asyncBatchIterate<T>(items: AsyncIterable<T>, batchSize: number, printBenchmark?: boolean): AsyncGenerator<T[], void, unknown>; /** * Convert an `AsyncIterable` to a generator * @param iter - AsyncIterable */ export declare function asyncIterableToGenerator<T>(iter: AsyncIterable<T>): AsyncGenerator<Awaited<T>, void, unknown>;