Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/skokov3812/promises-chain
The execution of the promises chain
https://github.com/skokov3812/promises-chain
chain javascript promise
Last synced: 15 days ago
JSON representation
The execution of the promises chain
- Host: GitHub
- URL: https://github.com/skokov3812/promises-chain
- Owner: skokov3812
- Created: 2019-10-15T08:34:44.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2019-10-16T02:59:10.000Z (about 5 years ago)
- Last Synced: 2024-12-03T08:12:09.651Z (about 1 month ago)
- Topics: chain, javascript, promise
- Language: JavaScript
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# promises-chain
The execution of the promises chainPromise.chain is actually a promise that takes an array of anonymous function with promises as an input (an iterable).
Return an array of promises results### Install
```
npm i promises-chain
``````js
let Promise1 = () => new Promise((resolve, reject) => {
setTimeout(() => {
resolve()
}, 1000);
})
...Promise.resolve(Promise1)
.then(Promise2)
.then(Promise3)
.then(Promise4)
Promise.chain([Promise1, Promise2, Promise3, Promise4])
```## Example:
```js
const promisesChain = require('promises-chain');Promise.chain([1,2,3,4,5].map(i => function(){
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log(i);
resolve(i*10)
}, 1000)
})
}))
.then(result => {
console.log('finish', result); // finish [ 10, 20, 30, 40, 50 ]
})
.catch(err => {
console.log('error', err)
})
```