UNPKG

@lzptec/concurrency

Version:

A Lightweight concurrency manager

102 lines (99 loc) 4.16 kB
import { S as SharedBase, B as BatchCommonOptions, a as BatchTaskOptions, b as BatchPredicateOptions, G as Group, R as RunnableTask, l as loop, I as Input, T as Task } from './shared-base-CsFeMl9A.cjs'; declare class Batch extends SharedBase<BatchCommonOptions> { #private; /** * Performs the specified `task` for each element in the `input`. * * It runs in batches with size defined by `batchSize`. * * @template A Input Type. * @param {BatchTaskOptions<A, any>} taskOptions Task Options. * @returns {Promise<void>} */ static forEach<A>(taskOptions: BatchTaskOptions<A, any>): Promise<void>; /** * Performs the specified `task` function on each element in the `input`, and returns an array that contains the results. * * It runs in batches with size defined by `batchSize`. * * @template A Input Type. * @template B Output Type. * @param {BatchTaskOptions<A, B>} taskOptions Task Options. * @returns {Promise<B[]>} */ static map<A, B>(taskOptions: BatchTaskOptions<A, B>): Promise<B[]>; /** * Performs the specified `task` function on each element in the `input`, * and creates a Promise that is resolved with an array of results when all of the tasks are resolve or reject. * * It runs in batches with size defined by `batchSize`. * * @template A Input Type. * @template B Output Type. * @param {BatchTaskOptions<A, B>} taskOptions Task Options. * @returns {Promise<PromiseSettledResult<B>[]>} */ static mapSettled<A, B>(taskOptions: BatchTaskOptions<A, B>): Promise<PromiseSettledResult<B>[]>; /** * Returns the elements that meet the condition specified in the `predicate` function. * * It runs in batches with size defined by `batchSize`. * * @template A Input Type. * @param {BatchPredicateOptions<A>} taskOptions Task Options. * @returns {Promise<A[]>} */ static filter<A>(taskOptions: BatchPredicateOptions<A>): Promise<A[]>; /** * Determines whether the specified `predicate` function returns true for any element of `input`. * * It runs in batches with size defined by `batchSize`. * * @template A Input Type. * @param {BatchPredicateOptions<A>} taskOptions Task Options. * @returns {Promise<boolean>} */ static some<A>(taskOptions: BatchPredicateOptions<A>): Promise<boolean>; /** * Returns the `input` value of the first `predicate` that resolves to true, and undefined otherwise. * * It runs in batches with size defined by `batchSize`. * * @template A Input Type. * @param {BatchPredicateOptions<A>} taskOptions Task Options. * @returns {Promise<A | undefined>} */ static find<A>(taskOptions: BatchPredicateOptions<A>): Promise<A | undefined>; /** * Determines whether all the elements of `input` satisfy the specified `predicate`. * * It runs in batches with size defined by `batchSize`. * * @template A Input Type. * @param {BatchPredicateOptions<A>} taskOptions Task Options. * @returns {Promise<boolean>} */ static every<A>(taskOptions: BatchPredicateOptions<A>): Promise<boolean>; /** * This method groups the elements of the `input` according to the string values returned by a provided `task`. * * The returned object has separate properties for each group, containing arrays with the elements in the group. * * It runs in batches with size defined by `batchSize`. * * @template A Input Type. * @param {BatchTaskOptions<A>} taskOptions Task Options. * @returns {Promise<Group<A>>} */ static group<A>(taskOptions: BatchTaskOptions<A, string | symbol>): Promise<Group<A>>; /** * * @param {BatchCommonOptions} options */ constructor(options: BatchCommonOptions); run<A, B>(task: RunnableTask<A, B>, ...args: A[]): Promise<B>; [loop]<A, B>(input: Input<A>, task: Task<A, B>): Promise<void>; set options(options: BatchCommonOptions); get options(): BatchCommonOptions; } export { Batch };