0.2.0 • Published 3 years ago

serialp v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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
0.1.2

3 years ago

0.2.0

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.1

3 years ago