From 6204dd4c372b8d9eea2a255d52494c21d63484f7 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Wed, 9 Nov 2022 11:23:34 +0200 Subject: [PATCH] util --- src/util/Util.js | 32 ++++++++++++++++++++++++++++++++ src/util/index.js | 3 +++ 2 files changed, 35 insertions(+) create mode 100644 src/util/Util.js create mode 100644 src/util/index.js diff --git a/src/util/Util.js b/src/util/Util.js new file mode 100644 index 0000000..32fcd79 --- /dev/null +++ b/src/util/Util.js @@ -0,0 +1,32 @@ +class Util { + + constructor () { + throw new Error('Utility class, may not be instantiated.'); + } + + static get now () { + return Math.floor(Date.now() / 1000); + } + + static wait (time) { + return new Promise((resolve) => { + setTimeout(resolve, time); + }); + } + + /** + * Fatally throw an error. Sends a signal to the parent process not to restart the process + * + * @static + * @param {Error} error Error to throw + * @memberof Util + */ + static fatal (error) { + process.send({ _fatal: true }, () => { + throw error; + }); + } + +} + +module.exports = Util; \ No newline at end of file diff --git a/src/util/index.js b/src/util/index.js new file mode 100644 index 0000000..3a1b91d --- /dev/null +++ b/src/util/index.js @@ -0,0 +1,3 @@ +module.exports = { + Util: require('./Util') +}; \ No newline at end of file