mirror of
https://github.com/tribufu/node-gamedig
synced 2026-05-06 07:07:33 +00:00
Additional async rewrite
This commit is contained in:
parent
efe12a00aa
commit
29ce0b82d0
24 changed files with 654 additions and 470 deletions
20
lib/Promises.js
Normal file
20
lib/Promises.js
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
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;
|
||||
Loading…
Add table
Add a link
Reference in a new issue