TS-Scribe - v1.2.0
    Preparing search index...

    Function waterfall

    • 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:

      const task1: Task<number> = () => Promise.resolve(1);
      const task2: Task<number> = () => Promise.resolve(2);
      const task3: Task<number> = () => Promise.resolve(3);

      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
      });

      Type Parameters

      • T

      Parameters

      • tasks: Task<T>[]

        An array of Promise-returning tasks to run in sequence.

      Returns Promise<T>

      A Promise that resolves with the result of the last task.

      If tasks is empty.

      const task1: Task<string> = () => Promise.resolve('Hello');
      const task2: Task<string> = () => Promise.resolve('World');

      waterfall([task1, task2]).then(result => {
      console.log(result); // "World"
      }).catch(error => {
      console.error(error); // In case of a rejection in any task
      });