Skip to content

Commit

Permalink
shared: fix waitFor (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yiin authored Sep 23, 2023
1 parent 9c0268f commit f028c4c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions shared/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});
});
}
Expand Down

0 comments on commit f028c4c

Please sign in to comment.