Skip to content

chainMaybePromise

function chainMaybePromise<T, R>(value, fn): MaybePromise<R>;

Defined in: resolve-maybe-promise.ts:30

Apply fn to a value that might be a Promise, staying synchronous when the value is synchronous: a plain value is transformed immediately (no microtask), a Promise is chained with .then.

This is the building block for sync/async-adaptive utilities — compose steps with it and an all-sync pipeline stays sync end to end.

Type Parameter
T
R
Parameter Type
value MaybePromise<T>
fn (value) => MaybePromise<R>

MaybePromise<R>

chainMaybePromise(1, (n) => n + 1); // 2 (sync)
chainMaybePromise(Promise.resolve(1), (n) => n + 1); // Promise<2>