promise-with-timeout
Version:
Limit the time to resolve a promise
25 lines (16 loc) • 509 B
Markdown
Limit the time to resolve a promise.
```
npm install --save promise-with-timeout
```
```javascript
import withTimeout from 'promise-with-timeout';
async function test() {
// Throw an error if there is no response after 10 seconds:
let response = await withTimeout(fetch('https://www.w3.org/'), 10000);
}
```
MIT