Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/exoticknight/parallelpromise
run promises with timeout, in parallel
https://github.com/exoticknight/parallelpromise
parallel promise typescript
Last synced: about 3 hours ago
JSON representation
run promises with timeout, in parallel
- Host: GitHub
- URL: https://github.com/exoticknight/parallelpromise
- Owner: exoticknight
- License: mit
- Created: 2018-03-25T07:03:37.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-05-05T10:08:17.000Z (over 1 year ago)
- Last Synced: 2024-11-19T09:26:56.632Z (about 7 hours ago)
- Topics: parallel, promise, typescript
- Language: TypeScript
- Size: 44.9 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ParallelPromise
run promises with timeout, in parallel
> you can alse check [serial-promise](https://www.npmjs.com/package/serial-promise)
## Install
```bash
npm install parallel-promise --save
```## Usage
```javascript
import ParallelPromise, { StatusCode } from 'parallel-promise'ParallelPromise(
[
() => {
// return a promise that resolves in 100ms
},
() => {
// return a promise that resolves in 3000ms
},
() => {
// return a promise that rejects in 100ms
},
() => {
// return a promise that rejects in 3000ms
},
],
[1000, 2000, 1000, 2000],
(progress) => {
// called whenever a promise's state is changed
// progress == {
// total: 4, total count of promise
// resolve: [], array of the index of the resolved promises
// reject: [], array of the index of the rejected promises
// timeout: [], array of the index of the timeouted promise
// }
}
).then(rets => {
// after 2000ms
// rets == [
// { status: StatusCode.RESOLVE, data:[your data] },
// { status: StatusCode.TIMEOUT, timeout: 2000 }
// { status: StatusCode.REJECT, err:[error] },
// { status: StatusCode.TIMEOUT, timeout: 2000 }
// ]
})// NOTE that there is not .catch here
```You can use async/await as well.
## StatusCode
| Status | StatusCode |
|---|---|
| RESOLVE | 0 |
| REJECT | 1 |
| TIMEOUT | -1 |## Test
```bash
npm run test
```## License
MIT