@vgerbot/async
    Preparing search index...

    Function waterfall

    Runs tasks in series, passing each result to the next task as input. Similar to series but with a clearer semantic focus on data flow through a pipeline.

    Each task receives:

    • The output of the previous task as its first argument
    • A cancellation token as its second argument

    The first task to execute (receives undefined as input)

    Additional tasks and optional options

    A cancellable handle that resolves to the last task's output

    const handle = waterfall(
    async (_, token) => {
    await token.sleep(10);
    return 5;
    },
    async (num, token) => {
    await token.sleep(10);
    return num * 2;
    },
    async (num, token) => {
    await token.sleep(10);
    return `Result: ${num}`;
    },
    );

    const result = await handle; // "Result: 10"
    const handle = waterfall(
    async () => fetch('/api/user'),
    async (response) => response.json(),
    async (data) => processUserData(data),
    );