import { type BatchCount } from '../grouping'; import { type Maybe } from '../value/maybe.type'; import { type PromiseOrValue } from './promise.type'; /** * Configuration for {@link performTaskLoop} without an initial value. */ export interface PerformTaskLoopConfig { /** * Produces the next value given the iteration index and the previous value. */ next: (i: number, prev: Maybe) => Promise; /** * Returns whether to continue looping. Called after each iteration with the current value and next index. */ checkContinue: (prev: Maybe, i: number) => PromiseOrValue; } /** * Configuration for {@link performTaskLoop} with a required initial value. */ export interface PerformTaskLoopWithInitConfig { /** * The initial value to start the loop with. */ initValue: O; /** * Produces the next value given the iteration index and the previous value. */ next: (i: number, prev: O) => Promise; /** * Returns whether to continue looping. Called after each iteration with the current value and next index. */ checkContinue: (prev: O, i: number) => PromiseOrValue; } /** * Executes an async task in a loop, calling `next` repeatedly until `checkContinue` returns false. * Optionally starts with an initial value. Returns the final value produced by the loop. * * @param config - Loop configuration with the next-value producer and continuation check. * @returns The final value produced by the last iteration. */ export declare function performTaskLoop(config: PerformTaskLoopWithInitConfig): Promise; export declare function performTaskLoop(config: PerformTaskLoopConfig): Promise; export declare function performTaskLoop(config: PerformTaskLoopConfig): Promise>; export declare function performTaskLoop(config: PerformTaskLoopConfig): Promise; /** * Configuration for {@link performTaskCountLoop} without an initial value. */ export interface PerformTaskCountLoopConfig extends Omit, 'checkContinue'> { /** * The number of iterations to perform. */ count: number; } /** * Configuration for {@link performTaskCountLoop} with a required initial value. */ export interface PerformTaskCountLoopWithInitConfig extends Omit, 'checkContinue'> { /** * The number of iterations to perform. */ count: number; } /** * Performs an async task loop a fixed number of times. A convenience wrapper around * {@link performTaskLoop} that automatically checks the iteration count. * * @param config - Loop configuration with the iteration count and next-value producer. * @returns The final value produced by the last iteration. */ export declare function performTaskCountLoop(config: PerformTaskCountLoopWithInitConfig): Promise; export declare function performTaskCountLoop(config: PerformTaskCountLoopConfig): Promise>; export declare function performTaskCountLoop(config: PerformTaskCountLoopConfig): Promise; /** * A function that creates a single item in a {@link performMakeLoop} iteration. * * @param i - The current iteration index. * @param made - The array of items created so far. */ export type PerformMakeLoopFunction = (i: number, made: O[]) => Promise; /** * Configuration for {@link performMakeLoop}. */ export interface PerformMakeLoopConfig { /** * The factory function to create each item. */ make: PerformMakeLoopFunction; /** * The total number of items to create. */ count: number; } /** * Creates an array of items by invoking a make function in a loop a specified number of times. * Each iteration receives the current index and the array of items created so far. * * @param config - Configuration with the make function and count. * @returns An array of all created items. */ export declare function performMakeLoop(config: PerformMakeLoopConfig): Promise; /** * A function that creates a batch of items in a {@link performBatchLoop} iteration. * * @param itemsToMake - The number of items to create in this batch. * @param i - The current batch index. * @param made - The array of batches created so far. */ export type PerformBatchLoopFunction = (itemsToMake: number, i: number, made: O[][]) => Promise; /** * Configuration for {@link performBatchLoop}. */ export interface PerformBatchLoopConfig extends BatchCount { /** * Factory function that creates a batch of items given the requested count. */ make: PerformBatchLoopFunction; } /** * Creates items in batches by dividing a total count into batch-sized chunks and * invoking the make function for each batch. * * @param config - Configuration with the make function and batch count parameters. * @returns A two-dimensional array where each inner array is a batch of created items. */ export declare function performBatchLoop(config: PerformBatchLoopConfig): Promise;