callThen
The callThen() function applies a callback directly to a value, or waits for a Promise before running the same callback.
Interactive example
Syntax
typescript
function callThen<
GenericInput extends unknown,
GenericOutput extends unknown,
>(
input: GenericInput,
TheFunction: (
input: Awaited<GenericInput>
) => GenericOutput,
): GenericInput extends Promise<unknown>
? Promise<Awaited<GenericOutput>>
: GenericOutput;Parameters
input: Direct value orPromiseto transform.TheFunction: Callback executed with the resolved value ofinput.
Return value
- If
inputis a direct value, returns the callback output. - If
inputis aPromise, returns aPromiseresolved with the callback output.
See also
externalPromise- Creates a promise controllable from the outsidepromiseObject- Resolves an object of promisesasyncPipe- Chains asynchronous transformations
