Skip to content
Snippets Groups Projects
Commit 2f0279aa authored by Benjamin Koltes's avatar Benjamin Koltes
Browse files

Merge branch 'fix/retryAfterFailRequests' into 'master'

If function in interval fails, retry it after initial ttl

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