Updated the sleep function to runAfter

- Added async
- Allowed functions to be run with it
- Added logging
This commit is contained in:
Logan Cusano
2023-02-25 01:12:10 -05:00
parent d9d90c7935
commit 4710dd4358

View File

@@ -5,9 +5,10 @@ const log = new DebugBuilder("server", "libUtils");
* sleep - sleep/wait
* @constructor
*/
exports.sleep = (ms) => new Promise((resolve) => {
setTimeout(resolve, ms);
})
exports.runAfter = async (toRun, timeout = 10000) => {
log.DEBUG(`Running '${toRun}' after ${timeout / 1000} seconds`);
setTimeout(toRun, timeout)
}
/**
* Normalize a port into a number, string, or false.