An open API service indexing awesome lists of open source software.

https://github.com/caiogondim/timeout-racer.js

🏎️ Timeout for promises race
https://github.com/caiogondim/timeout-racer.js

Last synced: about 2 months ago
JSON representation

🏎️ Timeout for promises race

Awesome Lists containing this project

README

        

# timeout-racer


Travis CI
JS standard style


`timeoutRacer` is a promise that rejects itself after `n` miliseconds passed as an argument.
Useful to put a timeout on races between Promises.

## Installation

```
npm install --save timeout-racer
```

## Usage

```js
Promise.race([
fooBarPromise(),
timeoutRacer(15000)
])
.then(() => {
// Will run if `fooBarPromise` resolves
})
.catch(() => {
// Will run if 15000 miliseconds passed
// or `fooBarPromise` rejects.
})
```

## Credits

- Icon by Corey Felter from the Noun Project

---

[caiogondim.com](https://caiogondim.com)  · 
GitHub [@caiogondim](https://github.com/caiogondim)  · 
Twitter [@caio_gondim](https://twitter.com/caio_gondim)