Skip to content
Snippets Groups Projects
Commit 5f081cf4 authored by Ayc0's avatar Ayc0
Browse files

fix: if function in interval fails, retry it after initial ttl

parent ed1759c9
No related branches found
No related tags found
No related merge requests found
......@@ -4,10 +4,16 @@ const { cert } = require('./config');
const interval = (fn, initialTTL, output = { id: null, clear: () => undefined }) => {
const timeoutID = setTimeout(async () => {
let TTL = fn();
let TTL;
try {
TTL = fn();
if (TTL instanceof Promise) {
TTL = await TTL;
}
} catch (error) {
console.error(error);
TTL = initialTTL;
}
const nextTTL = parseInt(TTL, 10) || initialTTL;
interval(fn, nextTTL, output);
}, initialTTL);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment