simple-promise-timeout
v0.0.8
Published
The function that returns promise timeout powered
Downloads
3
Readme
simple-promise-timeout
simple-promise-timeout
is a function that returns promise which is rejected if promise is not fulfilled whthin timeout given
Install
npm i simple-promise-timeout
Usage
import promiseTimeout from 'simple-promise-timeout'
const promise1 = new Promise((resolve, reject) => {
setTimeout(() => {
resolve('resolved')
}, 400)
})
promiseTimeout(promise1, 200) // will be rejected after 200ms
Custom error
const promise1 = new Promise((resolve, reject) => {
setTimeout(() => {
reject(Error('promise1 error'))
}, 400)
})
try {
await promiseTimeout(promise1, 200, Error('custom error'))
} catch (e) {
console.log(e.message) // print "custom error"
}