An array of asynchronous tasks to run in sequence.
Each task should follow the Task signature, which is a function that takes a callback.
A Promise that resolves with the result of the last task in the sequence.
const task1: Task<string> = (callback) => setTimeout(() => callback(null, "Hello"), 1000);
const task2: Task<string> = (callback) => setTimeout(() => callback(null, "World"), 1000);
waterfall([task1, task2]).then(result => {
console.log(result); // "World"
}).catch(error => {
console.error(error); // In case of an error in any task
});
Executes an array of asynchronous tasks in sequence. Each task is a function that takes a callback with an error or result, and the next task is executed only after the current one completes successfully.
It returns a Promise that resolves with the final result once all tasks are completed in order.
Example: