From f028c4c7a24aebd52d1f9fefee62b502a9809988 Mon Sep 17 00:00:00 2001 From: Yiin Date: Sun, 24 Sep 2023 01:57:48 +0300 Subject: [PATCH] shared: fix waitFor (#96) --- shared/js/utils.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/shared/js/utils.js b/shared/js/utils.js index 0431d610d..e24b80433 100644 --- a/shared/js/utils.js +++ b/shared/js/utils.js @@ -15,9 +15,14 @@ export function waitFor(cb, timeout) { return new Promise((resolve, reject) => { alt.Timers.everyTick(function () { - if (Date.now() > checkUntil) return reject(new Error("Timeout")); - if (cb()) return resolve(); - this.destroy(); + if (Date.now() > checkUntil) { + this.destroy(); + return reject(new Error("Timeout")); + } + if (cb()) { + this.destroy(); + return resolve(); + } }); }); }