serialp

    0.2.0 • Public • Published

    serialp

    Run promises in sequence

    Installation

    npm i serialp

    Basic example

    const timeout=duration=>()=>new Promise(
        resolve=>setTimeout(
            ()=>{
                resolve(duration)
            },duration
        )
    );
    const promises = [
        () => timeout(100),
        () => timeout(200)
    ];
    serialp(promises).then(
        results=>console.log(results) // [[true,100],[true,200]]
    );

    Usage

    serialp(arrayOfPromisesFunctions,observer)
      .then((x=>{}))
      .catch (x=>{}) // trigered only if observer is an async function
    1. x is an array of [success:boolean,result]

    2. observer is

    • either a function (index,success,result,results) which returns a boolean
      • if observer function returns false, promises execution stops,
      • observer function can be an async function
    • or a boolean
      • if true (default), all promises will be executed,
      • if false, promises execution will stop at first failure

    Install

    npm i serialp

    DownloadsWeekly Downloads

    3

    Version

    0.2.0

    License

    MIT

    Unpacked Size

    48.5 kB

    Total Files

    42

    Last publish

    Collaborators

    • thipages