Skip to content

fundamentool


async

Functions

checkNoop()

ts
function checkNoop(): boolean;

Defined in: src/async/checkNoop.ts:9

Default checkFn for async helpers that always allows continuation. Used when no custom check function is provided.

Returns

boolean

true – meaning the loop should continue.

Example

ts
checkNoop(); // => true

eachAsync()

ts
function eachAsync<A>(
   collection, 
   iteratee, 
   ctx?, 
checkFn?): Promise<A>;

Defined in: src/async/eachAsync.ts:17

Chooses async iterator (forEach for arrays, forIn for objects) and runs it.

Type Parameters

Type Parameter
A extends any[] | Record<string, any>

Parameters

ParameterTypeDefault valueDescription
collectionAundefinedArray or object to iterate.
iteratee(this, value, key, collection) => anyundefinedIteration function.
ctx?anyundefinedOptional this context.
checkFn?() => booleancheckNoopOptional function to additionally control loop continuation.

Returns

Promise<A>

Promise resolved with the input collection after all items are processed.

Example

ts
await eachAsync([1, 2], async (v) => console.log(v)); // logs 1, 2

eachParallel()

ts
function eachParallel<A>(
   collection, 
   iteratee, 
   ctx?, 
   taskLimit?, 
checkFn?): Promise<A>;

Defined in: src/async/parallel/eachParallel.ts:19

Chooses parallel iterator (forEach for arrays, forIn for objects via forInParallel) and runs it. This is a thin facade mirroring the old JS behaviour.

Type Parameters

Type Parameter
A extends any[] | Record<string, any>

Parameters

ParameterTypeDefault valueDescription
collectionAundefinedSource array or object.
iteratee(this, value, key, collection) => anyundefinedIteration function.
ctx?anyundefinedOptional this context.
taskLimit?numberundefinedMaximum number of concurrent tasks.
checkFn?() => booleancheckNoopOptional function to additionally control loop continuation.

Returns

Promise<A>

Promise resolved with the input collection.

Example

ts
await eachParallel([1, 2, 3], async (v) => process(v), null, 2); // 2 concurrent

filterAsync()

ts
function filterAsync<T>(
   items, 
   iteratee, 
   output, 
   ctx?, 
checkFn?): Promise<T[]>;

Defined in: src/async/filterAsync.ts:16

Asynchronously filters items using the provided iteratee.

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDefault valueDescription
itemsT[]undefinedSource array-like collection.
iteratee(this, value, index, items) => anyundefinedPredicate function returning truthy/falsey or a promise.
outputT[]undefinedOptional array to push accepted items into.
ctx?anyundefinedOptional this context for the iteratee.
checkFn?() => booleancheckNoopOptional function to additionally control loop continuation.

Returns

Promise<T[]>

Promise-like object resolved with the resulting array.

Example

ts
await filterAsync([1, 2, 3], async (v) => v > 1, null); // => [2, 3]

filterInAsync()

ts
function filterInAsync<T>(
   collection, 
   iteratee, 
   output?, 
   ctx?, 
checkFn?): Promise<Record<string, T>>;

Defined in: src/async/filterInAsync.ts:21

Asynchronous filter over array or object.

Unlike the legacy version, this helper expects iteratee to be a function; shorthand/normalize logic is removed.

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDefault valueDescription
collectionRecord<string, T>undefinedSource object.
iteratee(this, value, key, collection) => anyundefinedPredicate function.
output?Record<string, T>undefinedOptional output object.
ctx?anyundefinedOptional this context.
checkFn?() => booleancheckNoopOptional function to additionally control loop continuation.

Returns

Promise<Record<string, T>>

Promise resolved with resulting object.

Example

ts
await filterInAsync({ a: 1, b: 2 }, async (v) => v > 1); // => { b: 2 }

filterInParallel()

ts
function filterInParallel<T>(
   collection, 
   iteratee, 
   output?, 
   ctx?, 
   taskLimit?, 
checkFn?): Promise<Record<string, T>>;

Defined in: src/async/parallel/filterInParallel.ts:21

Parallel asynchronous filter over object.

Expects iteratee to be a function; shorthand/normalize logic is removed.

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDefault valueDescription
collectionRecord<string, T>undefinedSource object.
iteratee(this, value, key, collection) => anyundefinedPredicate function.
output?Record<string, T>undefinedOptional output object.
ctx?anyundefinedOptional this context.
taskLimit?numberundefinedMaximum number of concurrent tasks.
checkFn?() => booleancheckNoopOptional function to additionally control loop continuation.

Returns

Promise<Record<string, T>>

Promise resolved with resulting object.

Example

ts
await filterInParallel({ a: 1, b: 2 }, async (v) => v > 1, null, null, 2); // => { b: 2 }

filterParallel()

ts
function filterParallel<T>(
   items, 
   iteratee, 
   output, 
   ctx?, 
   taskLimit?, 
checkFn?): Promise<T[]>;

Defined in: src/async/parallel/filterParallel.ts:21

Parallel asynchronous filter over items.

First phase evaluates predicate in parallel and stores boolean flags, then reuses generic filterEach to build resulting array.

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDefault valueDescription
itemsT[]undefinedSource array-like collection.
iteratee(this, value, index, items) => anyundefinedPredicate function.
outputT[]undefinedOptional output array.
ctx?anyundefinedOptional this context.
taskLimit?numberundefinedMaximum concurrent tasks.
checkFn?() => booleancheckNoopOptional function to additionally control loop continuation.

Returns

Promise<T[]>

Promise resolved with resulting array.

Example

ts
await filterParallel([1, 2, 3], async (v) => v > 1, null, null, 2); // => [2, 3]

findAsync()

ts
function findAsync<T>(
   items, 
   iteratee, 
   ctx?, 
checkFn?): Promise<T>;

Defined in: src/async/findAsync.ts:15

Asynchronously finds first item that matches iteratee.

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDefault valueDescription
itemsT[]undefinedSource array-like collection.
iteratee(this, value, index, items) => anyundefinedPredicate function returning truthy/falsey or a promise.
ctx?anyundefinedOptional this context for the iteratee.
checkFn?() => booleancheckNoopOptional function to additionally control loop continuation.

Returns

Promise<T>

Promise-like object resolved with the found item or undefined.

Example

ts
await findAsync([1, 2, 3], async (v) => v === 2); // => 2

findInAsync()

ts
function findInAsync<T>(
   collection, 
   iteratee, 
   ctx?, 
checkFn?): Promise<T>;

Defined in: src/async/findInAsync.ts:18

Asynchronous find over array or object.

Expects iteratee to be a function; shorthand/normalize logic is removed.

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDefault valueDescription
collectionRecord<string, T>undefinedSource array-like collection.
iteratee(this, value, key, collection) => anyundefinedPredicate function.
ctx?anyundefinedOptional this context.
checkFn?() => booleancheckNoopOptional function to additionally control loop continuation.

Returns

Promise<T>

Promise resolved with the found item or undefined.

Example

ts
await findInAsync({ a: 1, b: 2 }, async (v) => v === 2); // => 2

findInParallel()

ts
function findInParallel<T>(
   collection, 
   iteratee, 
   ctx?, 
   taskLimit?, 
checkFn?): Promise<T>;

Defined in: src/async/parallel/findInParallel.ts:19

Parallel asynchronous find over object.

Expects iteratee to be a function; shorthand/normalize logic is removed.

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDefault valueDescription
collectionRecord<string, T>undefinedSource object.
iteratee(this, value, key, collection) => anyundefinedPredicate function.
ctx?anyundefinedOptional this context.
taskLimit?numberundefinedMaximum number of concurrent tasks.
checkFn?() => booleancheckNoopOptional function to additionally control loop continuation.

Returns

Promise<T>

Promise resolved with the found item or undefined.

Example

ts
await findInParallel({ a: 1, b: 2 }, async (v) => v === 2, null, 2); // => 2

findParallel()

ts
function findParallel<T>(
   items, 
   iteratee, 
   ctx?, 
   taskLimit?, 
checkFn?): Promise<T>;

Defined in: src/async/parallel/findParallel.ts:16

Parallel asynchronous find over array.

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDefault valueDescription
itemsT[]undefinedSource array.
iteratee(this, value, index, items) => anyundefinedPredicate function.
ctx?anyundefinedOptional this context.
taskLimit?numberundefinedMaximum concurrent tasks.
checkFn?() => booleancheckNoopOptional function to additionally control loop continuation.

Returns

Promise<T>

Promise resolved with the found item or undefined.

Example

ts
await findParallel([1, 2, 3], async (v) => v === 2, null, 2); // => 2

forEachAsync()

ts
function forEachAsync<T>(
   items, 
   iteratee, 
   ctx?, 
checkFn?): Promise<T[]>;

Defined in: src/async/forEachAsync.ts:15

Asynchronously iterates over an array-like items.

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDefault valueDescription
itemsT[]undefinedSource array-like collection.
iteratee(this, value, index, items) => anyundefinedIteration function, may return a value or a promise.
ctx?anyundefinedOptional this context for the iteratee.
checkFn?() => booleancheckNoopOptional function to additionally control loop continuation.

Returns

Promise<T[]>

Promise resolved with the original items array when the loop completes.

Example

ts
await forEachAsync([1, 2], async (v) => console.log(v)); // logs 1, 2

forEachParallel()

ts
function forEachParallel<T>(
   items, 
   fn, 
   ctx?, 
   taskLimit?, 
checkFn?): Promise<T[]>;

Defined in: src/async/parallel/forEachParallel.ts:16

Parallel asynchronous forEach over array.

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDefault valueDescription
itemsT[]undefinedSource array-like collection.
fn(this, value, index, items) => anyundefinedIteration function.
ctx?anyundefinedOptional this context.
taskLimit?numberundefinedMaximum number of concurrent tasks.
checkFn?() => booleancheckNoopOptional function to additionally control loop continuation.

Returns

Promise<T[]>

Promise resolved with the original items array.

Example

ts
await forEachParallel([1, 2, 3], async (v) => process(v), null, 2); // 2 concurrent

forInAsync()

ts
function forInAsync<T>(
   collection, 
   iteratee, 
   ctx?, 
checkFn?): Promise<Record<string, T>>;

Defined in: src/async/forInAsync.ts:16

Asynchronously iterates over object properties using entries.

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDefault valueDescription
collectionRecord<string, T>undefinedSource object.
iteratee(this, value, key, collection) => anyundefined-
ctx?anyundefinedOptional this context.
checkFn?() => booleancheckNoopOptional function to additionally control loop continuation.

Returns

Promise<Record<string, T>>

Promise resolved with the original collection when the loop completes.

Example

ts
await forInAsync({ a: 1 }, async (v, k) => console.log(k, v)); // logs 'a', 1

forInParallel()

ts
function forInParallel<T>(
   collection, 
   fn, 
   ctx?, 
   taskLimit?, 
checkFn?): Promise<Record<string, T>>;

Defined in: src/async/parallel/forInParallel.ts:17

Parallel asynchronous iteration over object properties.

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDefault valueDescription
collectionRecord<string, T>undefinedSource object.
fn(this, value, key, collection) => anyundefinedIteration function receiving (value, key, collection).
ctx?anyundefinedOptional this context.
taskLimit?numberundefinedMaximum number of concurrent tasks.
checkFn?() => booleancheckNoopOptional function to additionally control loop continuation.

Returns

Promise<Record<string, T>>

Promise resolved with the resulting object.

Example

ts
await forInParallel({ a: 1, b: 2 }, async (v, k) => process(k, v), null, 2);

intervalAsync()

ts
function intervalAsync(
   fn, 
   delayMs?, 
   args?, 
   self?): () => void;

Defined in: src/async/intervalAsync.ts:20

Runs fn periodically with the given delay.

If fn returns a promise, the next tick is scheduled after it settles. Returns a cancel function that stops subsequent executions.

Parameters

ParameterTypeDefault valueDescription
fn(...args) => anyundefinedFunction to execute periodically.
delayMsnumber0Delay in milliseconds.
args?ArrayLike<any>undefinedArguments to pass to the function.
self?anyundefinedOptional this context.

Returns

A cancel function that stops subsequent executions.

() => void

Example

ts
const stop = intervalAsync(() => fetch('/ping'), 5000);
stop(); // cancels further executions

loopAsync()

ts
function loopAsync(checkFn, statementFn): Promise<void>;

Defined in: src/async/loopAsync.ts:13

Asynchronous loop helper that repeatedly calls statementFn while checkFn is true.

Parameters

ParameterTypeDescription
checkFn() => booleanFunction to check if the loop should continue.
statementFn() => anyFunction to execute on each iteration.

Returns

Promise<void>

Promise resolved when the loop completes.

Example

ts
let i = 0;
await loopAsync(() => i < 3, async () => { i++; }); // i === 3

loopParallel()

ts
function loopParallel(
   checkFn, 
   statementFn, 
taskLimit?): Promise<any[]>;

Defined in: src/async/parallel/loopParallel.ts:17

Runs statementFn in parallel with a maximum of taskLimit concurrent tasks, advancing while checkFn returns true.

Parameters

ParameterTypeDefault valueDescription
checkFn() => booleanundefinedFunction to check if the loop should continue.
statementFn() => anyundefinedFunction to execute on each iteration.
taskLimitnumber1Maximum number of concurrent tasks.

Returns

Promise<any[]>

Promise resolved when the loop completes.

Example

ts
let i = 0;
await loopParallel(() => i < 6, async () => { i++; }, 3); // 3 concurrent tasks

mapAsync()

ts
function mapAsync<T, R>(
   items, 
   iteratee, 
   ctx?, 
checkFn?): Promise<R[]>;

Defined in: src/async/mapAsync.ts:15

Asynchronously maps an array-like items using iteratee.

Type Parameters

Type Parameter
T
R

Parameters

ParameterTypeDefault valueDescription
itemsT[]undefinedSource array-like collection.
iteratee(this, value, index, items) => R | Promise<R>undefinedMapping function, may return a value or a promise.
ctx?anyundefinedOptional this context for the iteratee.
checkFn?() => booleancheckNoopOptional function to additionally control loop continuation.

Returns

Promise<R[]>

Promise resolved with the resulting array.

Example

ts
await mapAsync([1, 2], async (v) => v * 2); // => [2, 4]

mapInAsync()

ts
function mapInAsync<T>(
   collection, 
   iteratee, 
   ctx?, 
checkFn?): Promise<Record<string, T>>;

Defined in: src/async/mapInAsync.ts:19

Asynchronous map over object.

Expects iteratee to be a function; shorthand/normalize logic is removed.

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDefault valueDescription
collectionRecord<string, T>undefinedSource object.
iteratee(this, value, key, collection) => T | Promise<T>undefinedMapping function.
ctx?anyundefinedOptional this context.
checkFn?() => booleancheckNoopOptional function to additionally control loop continuation.

Returns

Promise<Record<string, T>>

Promise resolved with resulting object.

Example

ts
await mapInAsync({ a: 1 }, async (v) => v * 2); // => { a: 2 }

mapInParallel()

ts
function mapInParallel<T>(
   collection, 
   iteratee, 
   ctx?, 
   taskLimit?, 
checkFn?): Promise<Record<string, T>>;

Defined in: src/async/parallel/mapInParallel.ts:18

Parallel asynchronous map over array or object.

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDefault valueDescription
collectionRecord<string, T>undefinedSource object.
iteratee(this, value, key, collection) => T | Promise<T>undefinedMapping function.
ctx?anyundefinedOptional this context.
taskLimit?numberundefinedMaximum number of concurrent tasks.
checkFn?() => booleancheckNoopOptional function to additionally control loop continuation.

Returns

Promise<Record<string, T>>

Promise resolved with resulting object.

Example

ts
await mapInParallel({ a: 1, b: 2 }, async (v) => v * 2, null, 2); // => { a: 2, b: 4 }

mapParallel()

ts
function mapParallel<T, R>(
   items, 
   iteratee, 
   ctx?, 
   taskLimit?, 
checkFn?): Promise<R[]>;

Defined in: src/async/parallel/mapParallel.ts:16

Parallel asynchronous map over items.

Type Parameters

Type Parameter
T
R

Parameters

ParameterTypeDefault valueDescription
itemsT[]undefinedSource array-like collection.
iteratee(this, value, index, items) => R | Promise<R>undefinedMapping function, may return a value or a promise.
ctx?anyundefinedOptional this context for the iteratee.
taskLimit?numberundefinedMaximum number of concurrent tasks.
checkFn?() => booleancheckNoopOptional function to additionally control loop continuation.

Returns

Promise<R[]>

Promise resolved with resulting array.

Example

ts
await mapParallel([1, 2, 3], async (v) => v * 2, null, 2); // => [2, 4, 6]

reduceAsync()

ts
function reduceAsync<T, A>(
   items, 
   iteratee, 
   accumulator, 
   ctx?, 
checkFn?): Promise<A>;

Defined in: src/async/reduceAsync.ts:18

Asynchronously reduces an array-like items from left to right.

Expects iteratee to be a function; shorthand/normalize logic is removed.

Type Parameters

Type Parameter
T
A

Parameters

ParameterTypeDefault valueDescription
itemsT[]undefinedSource array-like collection.
iteratee(this, acc, value, index, items) => A | Promise<A>undefinedReducer function, may return a value or a promise.
accumulatorAundefinedInitial accumulator value.
ctx?anyundefinedOptional this context for the iteratee.
checkFn?() => booleancheckNoopOptional function to additionally control loop continuation.

Returns

Promise<A>

Promise resolved with the final accumulator.

Example

ts
await reduceAsync([1, 2, 3], async (acc, v) => acc + v, 0); // => 6

reduceInAsync()

ts
function reduceInAsync<T, A>(
   collection, 
   iteratee, 
   accumulator, 
   ctx?, 
checkFn?): Promise<A>;

Defined in: src/async/reduceInAsync.ts:19

Asynchronous reduce over object.

Expects iteratee to be a function; shorthand/normalize logic is removed.

Type Parameters

Type Parameter
T
A

Parameters

ParameterTypeDefault valueDescription
collectionRecord<string, T>undefinedArray or object to reduce.
iteratee(this, acc, value, key, collection) => A | Promise<A>undefinedAsync-friendly reducer function.
accumulatorAundefinedInitial accumulator value.
ctx?anyundefinedOptional this context for the iteratee.
checkFn?() => booleancheckNoopOptional function to additionally control loop continuation.

Returns

Promise<A>

Promise resolved with the final accumulator.

Example

ts
await reduceInAsync({ a: 1, b: 2 }, async (acc, v) => acc + v, 0); // => 3

reduceInParallel()

ts
function reduceInParallel<T, A>(
   collection, 
   iteratee, 
   accumulator, 
   ctx?, 
   taskLimit?, 
checkFn?): Promise<A>;

Defined in: src/async/parallel/reduceInParallel.ts:18

Parallel asynchronous reduce over array or object.

Type Parameters

Type Parameter
T
A

Parameters

ParameterTypeDefault valueDescription
collectionRecord<string, T>undefinedSource object.
iteratee(this, acc, value, key, collection) => A | Promise<A>undefinedReducer function.
accumulatorAundefinedInitial accumulator value.
ctx?anyundefinedOptional this context for the iteratee.
taskLimit?numberundefinedMaximum number of concurrent tasks.
checkFn?() => booleancheckNoopOptional function to additionally control loop continuation.

Returns

Promise<A>

Promise resolved with the final accumulator.

Example

ts
await reduceInParallel({ a: 1, b: 2 }, async (acc, v) => acc + v, 0, null, 2); // => 3

reduceParallel()

ts
function reduceParallel<T, A>(
   input, 
   iteratee, 
   accumulator, 
   ctx?, 
   taskLimit?, 
checkFn?): Promise<A>;

Defined in: src/async/parallel/reduceParallel.ts:19

Parallel asynchronous reduce over an array-like input.

Iterations are scheduled in parallel with a configurable taskLimit.

Type Parameters

Type Parameter
T
A

Parameters

ParameterTypeDefault valueDescription
inputT[]undefinedSource array-like collection.
iteratee(this, acc, value, index, input) => A | Promise<A>undefinedFunction called for each item.
accumulatorAundefinedInitial accumulator value.
ctx?anyundefinedOptional this context for the iteratee.
taskLimit?numberundefinedMaximum number of concurrent tasks.
checkFn?() => booleancheckNoopOptional function to additionally control loop continuation.

Returns

Promise<A>

A promise resolved with the final accumulator.

Example

ts
await reduceParallel([1, 2, 3], async (acc, v) => acc + v, 0, null, 2); // => 6

sequence()

ts
function sequence<T>(fn, ctx?): (...args) => Promise<ReturnType<T>>;

Defined in: src/async/sequence.ts:13

Wraps function so that calls are executed sequentially: each waits for the previous.

Type Parameters

Type Parameter
T extends (...args) => any

Parameters

ParameterTypeDescription
fnTFunction to wrap.
ctx?anyOptional this context for the function.

Returns

Wrapped function that returns a Promise.

(...args) => Promise<ReturnType<T>>

Example

ts
const seq = sequence(fetchData);
seq(); // first call starts immediately
seq(); // waits for first to finish, then runs

sequenceDelay()

ts
function sequenceDelay<T>(
   fn, 
   delayMs, 
ctx?): (...args) => Promise<ReturnType<T>>;

Defined in: src/async/sequenceDelay.ts:15

Like sequence, but adds a delay before each execution.

Type Parameters

Type Parameter
T extends (...args) => any

Parameters

ParameterTypeDescription
fnTFunction to wrap.
delayMsnumberDelay in milliseconds.
ctx?anyOptional this context for the function.

Returns

Wrapped function that returns a Promise.

(...args) => Promise<ReturnType<T>>

Example

ts
const delayedSave = sequenceDelay(save, 300);
delayedSave(); // waits 300ms before executing, queues subsequent calls

withDelayAsync()

ts
function withDelayAsync<T>(
   fn, 
   delayMs, 
ctx?): (...args) => Promise<ReturnType<T>>;

Defined in: src/async/withDelayAsync.ts:13

Debounced async wrapper: schedules function execution after delayMs. Returns a promise resolved with the last call result.

Type Parameters

Type Parameter
T extends (...args) => any

Parameters

ParameterTypeDescription
fnTFunction to wrap.
delayMsnumberDelay in milliseconds.
ctx?anyOptional this context for the function.

Returns

Wrapped debounced function that returns a Promise.

(...args) => Promise<ReturnType<T>>

Example

ts
const debounced = withDelayAsync(search, 300);
debounced('query'); // => Promise, resolves after 300ms

withLatencyProvider()

ts
function withLatencyProvider(requestLatency): <T>(fn, args, ctx) => Promise<T>;

Defined in: src/async/withLatencyProvider.ts:15

Ensures that calls to fn take at least requestLatency ms. Useful for smoothing UI latency so fast responses don't cause visual flicker.

Parameters

ParameterTypeDescription
requestLatencynumberMinimum response time in milliseconds.

Returns

A function that runs fn with the given minimum latency.

<T>(fn, args, ctx) => Promise<T>

Example

ts
const run = withLatencyProvider(500);
await run(fetchData, [], ctx); // always takes at least 500ms

MIT License