gamedig
Version:
Query for the status of any game server in Node.JS
19 lines (18 loc) • 449 B
JavaScript
export default class Promises {
static createTimeout (timeoutMs, timeoutMsg) {
let cancel = null
const wrapped = new Promise((resolve, reject) => {
const timeout = setTimeout(
() => {
reject(new Error(timeoutMsg + ' - Timed out after ' + timeoutMs + 'ms'))
},
timeoutMs
)
cancel = () => {
clearTimeout(timeout)
}
})
wrapped.cancel = cancel
return wrapped
}
}