https://github.com/thipages/serialp
Promises in sequence
https://github.com/thipages/serialp
javascript promises sequence
Last synced: about 2 months ago
JSON representation
Promises in sequence
- Host: GitHub
- URL: https://github.com/thipages/serialp
- Owner: thipages
- License: mit
- Created: 2021-03-05T23:27:23.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2021-03-09T11:14:01.000Z (about 4 years ago)
- Last Synced: 2024-04-25T20:44:54.468Z (about 1 year ago)
- Topics: javascript, promises, sequence
- Language: JavaScript
- Homepage:
- Size: 14.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# serialp
Run promises in sequence## Installation
_npm i serialp_## Basic example
```javascript
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
```javascriptserialp(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