export type Task = ( previousValue: ValueType ) => ReturnType | PromiseLike; export type InitialTask = () => ReturnType | PromiseLike; /** Run promise-returning & async functions in series, each passing its result to the next. @param tasks - Functions are expected to return a value. If a `Promise` is returned, it's awaited before continuing with the next task. @param 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 ``` import pWaterfall from 'p-waterfall'; const tasks = [ initialValue => getEmoji(initialValue), previousValue => `I ❤️ ${previousValue}` ]; console.log(await pWaterfall(tasks, 'unicorn')); //=> 'I ❤️ 🦄' ``` **Tip:** Use [`as const`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-4.html#const-assertions) to improve type inference when defining task arrays outside of `pWaterfall()`: ``` const tasks = [ () => 'unicorn', previousValue => `I ❤️ ${previousValue}`, string => string.length ] as const; await pWaterfall(tasks); // Returns a `Promise` (the return type of the last task) ``` */ export default function pWaterfall( tasks: readonly [ InitialTask ] ): Promise; export default function pWaterfall( tasks: readonly [ InitialTask, Task ] ): Promise; export default function pWaterfall( tasks: readonly [ InitialTask, Task, Task ] ): Promise; export default function pWaterfall( tasks: readonly [ InitialTask, Task, Task, Task ] ): Promise; export default function pWaterfall( tasks: readonly [ InitialTask, Task, Task, Task, Task ] ): Promise; export default function pWaterfall( tasks: readonly [ InitialTask, Task, Task, Task, Task, Task ] ): Promise; export default function pWaterfall< ValueType1, ValueType2, ValueType3, ValueType4, ValueType5, ValueType6, ReturnType >( tasks: readonly [ InitialTask, Task, Task, Task, Task, Task, Task ] ): Promise; export default function pWaterfall< ValueType1, ValueType2, ValueType3, ValueType4, ValueType5, ValueType6, ValueType7, ReturnType >( tasks: readonly [ InitialTask, Task, Task, Task, Task, Task, Task, Task ] ): Promise; export default function pWaterfall( tasks: readonly [ Task ], initialValue: ValueType1 ): Promise; export default function pWaterfall( tasks: readonly [ Task, Task ], initialValue: ValueType1 ): Promise; export default function pWaterfall( tasks: readonly [ Task, Task, Task ], initialValue: ValueType1 ): Promise; export default function pWaterfall( tasks: readonly [ Task, Task, Task, Task ], initialValue: ValueType1 ): Promise; export default function pWaterfall( tasks: readonly [ Task, Task, Task, Task, Task ], initialValue: ValueType1 ): Promise; export default function pWaterfall< ValueType1, ValueType2, ValueType3, ValueType4, ValueType5, ValueType6, ReturnType >( tasks: readonly [ Task, Task, Task, Task, Task, Task ], initialValue: ValueType1 ): Promise; export default function pWaterfall< ValueType1, ValueType2, ValueType3, ValueType4, ValueType5, ValueType6, ValueType7, ReturnType >( tasks: readonly [ Task, Task, Task, Task, Task, Task, Task ], initialValue: ValueType1 ): Promise; export default function pWaterfall< ValueType1, ValueType2, ValueType3, ValueType4, ValueType5, ValueType6, ValueType7, ValueType8, ReturnType >( tasks: readonly [ Task, Task, Task, Task, Task, Task, Task, Task ], initialValue: ValueType1 ): Promise; export default function pWaterfall( tasks: Iterable>, initialValue?: unknown ): Promise;