/* xeslint-disable */ let keepChecking = false; const DEFAULT_POLLING_INTERVAL = 60000; //const DEFAULT_POLLING_INTERVAL = 5000; const MAX_POLLING_INTERVAL = 10 * 60 * 1000; //10 minutes maximum wait time export default { async startPolling() { if (keepChecking == true) { return; } keepChecking = true; //initial delay so it fetchs "immediately" let pollingInterval = 3000; let status = null; while (keepChecking == true) { try { await window.$gz.util.sleepAsync(pollingInterval); if (keepChecking && window.$gz.store.state.authenticated) { status = await window.$gz.api.get("notify/new-count"); if (status.error) { throw new Error(status.error); } else { window.$gz.store.commit("setNewNotificationCount", status.data); //success so go to default in case it was changed by an error pollingInterval = DEFAULT_POLLING_INTERVAL; } } else { keepChecking = false; } } catch (error) { //fixup if fails on very first iteration with initial short polling interval if (pollingInterval < DEFAULT_POLLING_INTERVAL) { pollingInterval = DEFAULT_POLLING_INTERVAL; } pollingInterval *= 1.5; if (pollingInterval > MAX_POLLING_INTERVAL) { pollingInterval = MAX_POLLING_INTERVAL; } } } }, stopPolling() { keepChecking = false; } };