mirror of
https://github.com/gamedig/node-gamedig.git
synced 2024-11-16 16:58:32 +01:00
21 lines
549 B
JavaScript
21 lines
549 B
JavaScript
|
class Promises {
|
||
|
static createTimeout(timeoutMs, timeoutMsg) {
|
||
|
let cancel = null;
|
||
|
const wrapped = new Promise((res, rej) => {
|
||
|
const timeout = setTimeout(
|
||
|
() => {
|
||
|
rej(new Error(timeoutMsg + " - Timed out after " + timeoutMs + "ms"));
|
||
|
},
|
||
|
timeoutMs
|
||
|
);
|
||
|
cancel = () => {
|
||
|
clearTimeout(timeout);
|
||
|
};
|
||
|
});
|
||
|
wrapped.cancel = cancel;
|
||
|
return wrapped;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
module.exports = Promises;
|