https://github.com/imcuttle/prom-race
A better `Promise.race`
https://github.com/imcuttle/prom-race
Last synced: about 1 year ago
JSON representation
A better `Promise.race`
- Host: GitHub
- URL: https://github.com/imcuttle/prom-race
- Owner: imcuttle
- License: mit
- Created: 2019-01-15T06:12:15.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-01-07T14:00:14.000Z (over 4 years ago)
- Last Synced: 2025-03-18T12:21:19.074Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 87.9 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: License
Awesome Lists containing this project
README
# prom-race
[](https://travis-ci.org/imcuttle/prom-race)
[](https://codecov.io/github/imcuttle/prom-race?branch=master)
[](https://www.npmjs.com/package/prom-race)
[](https://www.npmjs.com/package/prom-race)
[](https://prettier.io/)
[](https://conventionalcommits.org)
> A better `Promise.race`
## Why use It?
1. `Promise.race()` returning a forever pending promise when supplied an empty iterable, but `prom-race` will NOT!
2. `prom-race` will call the others promises' `cancel` method if possible.
## Installation
```bash
npm install prom-race
# or use yarn
yarn add prom-race
```
## Usage
```javascript
const promRace = require('prom-race')
```
## API
### race
[index.js:14-58](https://github.com/imcuttle/prom-race/blob/afe739cf5ae833b7a169ca57bcb4c14b63ed20fd/index.js#L14-L58 'Source code on GitHub')
#### Parameters
- `iterable` {Iterable}
An iterable object, such as an Array.
- `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** {{}}
- `options.cancelWhenFinished` {boolean} - Whether call the others promises' `cancel` method. (optional, default `true`)
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<any>**
## Contributing
- Fork it!
- Create your new branch:
`git checkout -b feature-new` or `git checkout -b fix-which-bug`
- Start your magic work now
- Make sure npm test passes
- Commit your changes:
`git commit -am 'feat: some description (close #123)'` or `git commit -am 'fix: some description (fix #123)'`
- Push to the branch: `git push`
- Submit a pull request :)
## Authors
This library is written and maintained by imcuttle, moyuyc95@gmail.com.
## License
MIT - [imcuttle](https://github.com/imcuttle) 🐟