Packages

Give clients/browser an identifier that can be used to send messages to/from/between clients. In essence a pid.

Current section

Files

Jump to
gen_browser src promiseTimeout.js
Raw

src/promiseTimeout.js

export default function promiseTimeout(promise, milliseconds){
// Create a promise that rejects in <ms> milliseconds
let timeout = new Promise((resolve, reject) => {
let id = setTimeout(() => {
clearTimeout(id);
reject('Timed out in '+ milliseconds + 'ms.')
}, milliseconds)
})
// Returns a race between our timeout and the passed in promise
return Promise.race([
promise,
timeout
])
}