Skip to content

promiseChain

Chain async functions together

141 bytes
since v12.6.0

Usage

Creates a function that executes multiple functions in the same order as they are passed in arguments. Each function may be synchronous or asynchronous. The result of each function is passed to the next function. The final result is returned as a Promise.

import * as _ from 'radashi'
const func1 = vi.fn((a, b) => a + b)
const func2 = vi.fn(async n => n * 2)
const func3 = vi.fn(async n => `Your Value is ${n}`)
const chained = await _.promiseChain(func1, func2, func3)
await chained(5, 2) // => "Your Value is 14"