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 Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
T |
R |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
MaybePromise<T> |
fn |
(value) => MaybePromise<R> |
Returns
Section titled “Returns”MaybePromise<R>
Example
Section titled “Example”chainMaybePromise(1, (n) => n + 1); // 2 (sync)chainMaybePromise(Promise.resolve(1), (n) => n + 1); // Promise<2>