From 4710dd435880312689dc35983b46d0d321746102 Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Sat, 25 Feb 2023 01:12:10 -0500 Subject: [PATCH] Updated the sleep function to runAfter - Added async - Allowed functions to be run with it - Added logging --- libUtils.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libUtils.js b/libUtils.js index 4cf4494..b90f07d 100644 --- a/libUtils.js +++ b/libUtils.js @@ -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.