Executes an array of Promise-returning tasks in sequence, resolving with the result of the last task.
Each task runs only after the previous one resolves; if any task rejects, execution stops immediately.
waterfall([task1, task2, task3]).then(result=> { console.log(result); // 3 (final result from task3) }).catch(error=> { console.error(error); // If any task rejects, it will be caught here });
waterfall([task1, task2]).then(result=> { console.log(result); // "World" }).catch(error=> { console.error(error); // In case of a rejection in any task });
Executes an array of Promise-returning tasks in sequence, resolving with the result of the last task. Each task runs only after the previous one resolves; if any task rejects, execution stops immediately.
Example: