p-waterfall
- Version 3.0.0
- Published
- 9.75 kB
- 1 dependency
- MIT license
Install
npm i p-waterfall
yarn add p-waterfall
pnpm add p-waterfall
Overview
Run promise-returning & async functions in series, each passing its result to the next
Index
Functions
Type Aliases
Functions
function pWaterfall
pWaterfall: { <ReturnType>(tasks: readonly [InitialTask<ReturnType>]): Promise<ReturnType>; <ValueType1, ReturnType>( tasks: readonly [InitialTask<ValueType1>, Task<ValueType1, ReturnType>] ): Promise<ReturnType>; <ValueType1, ValueType2, ReturnType>( tasks: readonly [ InitialTask<ValueType1>, Task<ValueType1, ValueType2>, Task<ValueType2, ReturnType> ] ): Promise<ReturnType>; <ValueType1, ValueType2, ValueType3, ReturnType>( tasks: readonly [ InitialTask<ValueType1>, Task<ValueType1, ValueType2>, Task<ValueType2, ValueType3>, Task<ValueType3, ReturnType> ] ): Promise<ReturnType>; <ValueType1, ValueType2, ValueType3, ValueType4, ReturnType>( tasks: readonly [ InitialTask<ValueType1>, Task<ValueType1, ValueType2>, Task<ValueType2, ValueType3>, Task<ValueType3, ValueType4>, Task<ValueType4, ReturnType> ] ): Promise<ReturnType>; <ValueType1, ValueType2, ValueType3, ValueType4, ValueType5, ReturnType>( tasks: readonly [ InitialTask<ValueType1>, Task<ValueType1, ValueType2>, Task<ValueType2, ValueType3>, Task<ValueType3, ValueType4>, Task<ValueType4, ValueType5>, Task<ValueType5, ReturnType> ] ): Promise<ReturnType>; < ValueType1, ValueType2, ValueType3, ValueType4, ValueType5, ValueType6, ReturnType >( tasks: readonly [ InitialTask<ValueType1>, Task<ValueType1, ValueType2>, Task<ValueType2, ValueType3>, Task<ValueType3, ValueType4>, Task<ValueType4, ValueType5>, Task<ValueType5, ValueType6>, Task<ValueType6, ReturnType> ] ): Promise<ReturnType>; < ValueType1, ValueType2, ValueType3, ValueType4, ValueType5, ValueType6, ValueType7, ReturnType >( tasks: readonly [ InitialTask<ValueType1>, Task<ValueType1, ValueType2>, Task<ValueType2, ValueType3>, Task<ValueType3, ValueType4>, Task<ValueType4, ValueType5>, Task<ValueType5, ValueType6>, Task<ValueType6, ValueType7>, Task<ValueType7, ReturnType> ] ): Promise<ReturnType>; <ValueType1, ReturnType>( tasks: readonly [Task<ValueType1, ReturnType>], initialValue: ValueType1 ): Promise<ReturnType>; <ValueType1, ValueType2, ReturnType>( tasks: readonly [Task<ValueType1, ValueType2>, Task<ValueType2, ReturnType>], initialValue: ValueType1 ): Promise<ReturnType>; <ValueType1, ValueType2, ValueType3, ReturnType>( tasks: readonly [ Task<ValueType1, ValueType2>, Task<ValueType2, ValueType3>, Task<ValueType3, ReturnType> ], initialValue: ValueType1 ): Promise<ReturnType>; <ValueType1, ValueType2, ValueType3, ValueType4, ReturnType>( tasks: readonly [ Task<ValueType1, ValueType2>, Task<ValueType2, ValueType3>, Task<ValueType3, ValueType4>, Task<ValueType4, ReturnType> ], initialValue: ValueType1 ): Promise<ReturnType>; <ValueType1, ValueType2, ValueType3, ValueType4, ValueType5, ReturnType>( tasks: readonly [ Task<ValueType1, ValueType2>, Task<ValueType2, ValueType3>, Task<ValueType3, ValueType4>, Task<ValueType4, ValueType5>, Task<ValueType5, ReturnType> ], initialValue: ValueType1 ): Promise<ReturnType>; < ValueType1, ValueType2, ValueType3, ValueType4, ValueType5, ValueType6, ReturnType >( tasks: readonly [ Task<ValueType1, ValueType2>, Task<ValueType2, ValueType3>, Task<ValueType3, ValueType4>, Task<ValueType4, ValueType5>, Task<ValueType5, ValueType6>, Task<ValueType6, ReturnType> ], initialValue: ValueType1 ): Promise<ReturnType>; < ValueType1, ValueType2, ValueType3, ValueType4, ValueType5, ValueType6, ValueType7, ReturnType >( tasks: readonly [ Task<ValueType1, ValueType2>, Task<ValueType2, ValueType3>, Task<ValueType3, ValueType4>, Task<ValueType4, ValueType5>, Task<ValueType5, ValueType6>, Task<ValueType6, ValueType7>, Task<ValueType7, ReturnType> ], initialValue: ValueType1 ): Promise<ReturnType>; < ValueType1, ValueType2, ValueType3, ValueType4, ValueType5, ValueType6, ValueType7, ValueType8, ReturnType >( tasks: readonly [ Task<ValueType1, ValueType2>, Task<ValueType2, ValueType3>, Task<ValueType3, ValueType4>, Task<ValueType4, ValueType5>, Task<ValueType5, ValueType6>, Task<ValueType6, ValueType7>, Task<ValueType7, ValueType8>, Task<ValueType8, ReturnType> ], initialValue: ValueType1 ): Promise<ReturnType>; ( tasks: Iterable<Task<unknown, unknown>>, initialValue?: unknown ): Promise<unknown>;};
Run promise-returning & async functions in series, each passing its result to the next.
Parameter tasks
Functions are expected to return a value. If a
Promise
is returned, it's awaited before continuing with the next task.Parameter initialValue
Value to use as
previousValue
in the first task.Returns
Resolves when all promises returned from calling the functions in
tasks
are fulfilled, or rejects if any of the promises reject. The fulfilled value is the value returned from the last task.Example 1
import pWaterfall from 'p-waterfall';const tasks = [initialValue => getEmoji(initialValue),previousValue => `I ❤️ ${previousValue}`];console.log(await pWaterfall(tasks, 'unicorn'));//=> 'I ❤️ 🦄'
Type Aliases
type InitialTask
type InitialTask<ReturnType> = () => ReturnType | PromiseLike<ReturnType>;
type Task
type Task<ValueType, ReturnType> = ( previousValue: ValueType) => ReturnType | PromiseLike<ReturnType>;
Package Files (1)
Dependencies (1)
Dev Dependencies (3)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/p-waterfall
.
- Markdown[](https://www.jsdocs.io/package/p-waterfall)
- HTML<a href="https://www.jsdocs.io/package/p-waterfall"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 2964 ms. - Missing or incorrect documentation? Open an issue for this package.