@lzptec/concurrency
Version:
A Lightweight concurrency manager
82 lines (79 loc) • 3.8 kB
TypeScript
export { Batch } from './batch.js';
export { Concurrency } from './concurrency.js';
export { Throttle } from './throttle.js';
export { Semaphore, SemaphoreLock } from './semaphore.js';
export { Lock } from './lock.js';
import { I as Input, T as Task, G as Group, S as SharedBase } from './shared-base-CsFeMl9A.js';
type InputType<TValue> = TValue extends Input<infer TResult> ? TResult : never;
type Overwrite<T, U> = Omit<T, keyof U> & U;
type SingleValueChain<TInput extends Input<any>, TValue = InputType<TInput>> = Overwrite<Chain<TInput, TValue>, {
runWith(runner: SharedBase<any>): Promise<TValue>;
}>;
declare class Chain<TInput extends Input<any>, TValue = InputType<TInput>> {
#private;
constructor(input: TInput);
/**
* Performs the specified `task` function on each element in the `input`, and returns an `Chain` that contains the results.
*
* @template TValue Input Type.
* @template TNew Output Type.
* @param {Task<TValue, TNew>} task task to run.
* @returns {Chain<TNew[], TNew>}
*/
map<TNew>(task: Task<TValue, TNew>): Chain<TNew[], TNew>;
/**
* Performs the specified `task` function on each element in the `input`,
* and returns an `Chain` that contains all of the tasks results as resolve or reject.
*
* @template TValue Input Type.
* @template TNew Output Type.
* @param {Task<TValue, TNew>} task task to run.
* @returns {Chain<PromiseSettledResult<TNew>[], PromiseSettledResult<TNew>>}
*/
mapSettled<TNew>(task: Task<TValue, TNew>): Chain<PromiseSettledResult<TNew>[], PromiseSettledResult<TNew>>;
/**
* Returns an `Chain` that contains the elements that meet the condition specified in the `predicate` function.
*
* @template TValue Input Type.
* @param {Task<TValue, boolean>} predicate predicate to run.
* @returns {Chain<TValue[], TValue>}
*/
filter(predicate: Task<TValue, boolean>): Chain<TValue[], TValue>;
/**
* Returns an `Chain` that contains whether the specified `predicate` function returns true for any element of `input`.
*
* @template TValue Input Type.
* @param {Task<TValue, boolean>} predicate predicate to run.
* @returns {SingleValueChain<boolean[], boolean>}
*/
some(predicate: Task<TValue, boolean>): SingleValueChain<boolean[], boolean>;
/**
* Returns the `input` value of the first `predicate` that resolves to true, and undefined otherwise.
*
* @template TValue Input Type.
* @param {Task<TValue, boolean>} predicate predicate to run.
* @returns {SingleValueChain<boolean[], TValue | undefined>}
*/
find(predicate: Task<TValue, boolean>): SingleValueChain<TValue[], TValue | undefined>;
/**
* Determines whether all the elements of `input` satisfy the specified `predicate`.
*
* @template TValue Input Type.
* @param {Task<TValue, boolean>} predicate predicate to run.
* @returns {SingleValueChain<boolean[], TValue | undefined>}
*/
every(predicate: Task<TValue, boolean>): SingleValueChain<boolean[], boolean>;
/**
* This method groups the elements of the `input` according to the string or symbol values returned by a provided `task`.
*
* The returned object has separate properties for each group, containing arrays with the elements in the group.
*
* @template TValue Input Type.
* @template TNew Output Type.
* @param {Task<TValue, string | symbol>} task task to run.
* @returns {Chain<Group<TValue>[], Group<TValue>>}
*/
group(task: Task<TValue, string | symbol>): Chain<Group<TValue>[], Group<TValue>>;
runWith<TResult = TValue[]>(runner: SharedBase<any>): Promise<TResult>;
}
export { Chain, type InputType, type SingleValueChain };