Skip to content

Commit

Permalink
fix: stopTimeout
Browse files Browse the repository at this point in the history
  • Loading branch information
Faf4a committed Jun 28, 2024
1 parent 0fa7cf6 commit 8485629
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/functions/stopTimeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@ module.exports = async (d) => {
if (data.err) return d.error(data.err);

const [id] = data.inside.splits;
const MAX_SAFE_INTEGER = 0x7FFFFFFF;

const timeout = await d.client.db.get(
"__aoijs_vars__",
"setTimeout",
id,
);
if (!timeout) return d.error(`Timeout with ID: ${id} not found.`);
if (!timeout) return d.error(`AoiError: Timeout ID ${id} not found.`);

timeout.value.__timeoutIds__.forEach((x) => clearTimeout(x));
timeout.value.__pulseIds__?.forEach((x) => clearInterval(x));
if ((timeout.value.__duration__ - Date.now()) <= MAX_SAFE_INTEGER) {
clearTimeout(timeout.value.__id__);
} else {
clearInterval(timeout.value.__id__)
}

await d.client.db.delete("__aoijs_vars__", "setTimeout", id);

Expand Down

0 comments on commit 8485629

Please sign in to comment.