Nebulous Puffy Marshmallows

    p-waterfall
    TypeScript icon, indicating that this package has built-in type declarations

    3.0.0 • Public • Published

    p-waterfall

    Run promise-returning & async functions in series, each passing its result to the next

    Install

    $ npm install p-waterfall
    

    Usage

    import pWaterfall from 'p-waterfall';
    
    const tasks = [
    	initialValue => getEmoji(initialValue),
    	previousValue => `I ❤️ ${previousValue}`
    ];
    
    console.log(await pWaterfall(tasks, 'unicorn'));
    //=> 'I ❤️ 🦄'

    API

    pWaterfall(tasks, initialValue?)

    Returns a Promise that is fulfilled 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.

    tasks

    Type: Iterable<Function>

    Functions are expected to return a value. If a Promise is returned, it's awaited before continuing with the next task.

    initialValue

    Type: unknown

    Value to use as previousValue in the first task.

    Related


    Get professional support for this package with a Tidelift subscription
    Tidelift helps make open source sustainable for maintainers while giving companies
    assurances about security, maintenance, and licensing for their dependencies.

    Install

    npm i p-waterfall

    DownloadsWeekly Downloads

    1,119,168

    Version

    3.0.0

    License

    MIT

    Unpacked Size

    9.75 kB

    Total Files

    5

    Last publish

    Collaborators

    • sindresorhus