function loop(force = false) {
        /*
         * If the interval call is already running AND the elapsed time since the previous pending call is greater than
         * the `loop debounce ms`. Return it.
         *
         * Imagine the following scenario:
         * A user has performed an action and we call the event manager directly. The event call takes 2 seconds to return.
         * In those 2 seconds, before the event call has returned, the user performs another action and we need new data
         * from the event log. In this case it falls through and recalls again.
         *
         * Otherwise, if the application wants to refresh inside the `loop debounce ms` (and we're not forcing a refresh),
         * we return the old call because we don't want to spam the event log either.
         */
        if (!force && STATE.loopCall && Date.now() - STATE.loopTime < EVENTS_MS.LOOP_DEBOUNCE_MS) {
            return STATE.loopCall;
        }

        stop();

        STATE.loopTime = Date.now();

        return (STATE.loopCall = get()
            .then((data) => {
                STATE.loopCall = undefined;
                STATE.loopTime = 0;

                // Close any retry notification.
                closeRetryNotification();

                stop();
                STATE.retryIndex = 0;
                start();

                return manage(data);
            })
            .catch((e) => {
                STATE.loopCall = undefined;
                STATE.loopTime = 0;

                stop();

                /**
                 * If the custom error code is invalid event id, null it and
                 * restart in 30 seconds (to prevent spamming) in case the FE
                 * is doing something wrong.
                 */
                const { data = {}, status } = e;
                if (data.Code === EVENTS_ID_INVALID) {
                    setEventID(undefined);
                    return start();
                }

                // Leaving the notification here for now pending discussion about the behavior.
                if (status === 0 || status === -1) {
                    showRetryNotification();
                }

                /**
                 * Error handling:
                 * 1) It could have failed because the network is offline, it will either restart from the resurrecter,
                 *    or the user hitting "retry now".
                 * 2) It could have failed because the API is down, so increase the retry index and start the timeout again.
                 */
                if (STATE.retryIndex < FIBONACCI.length - 1) {
                    STATE.retryIndex++;
                }
                start();

                throw e;
            }));
    }
/**
     * Call the event manager, and if it succeeds, set up the loop to call it again after x seconds.
     * @param {Boolean} force Force the event call to happen, ignoring the debounce.
     * @returns {Promise}
     */
Call the event manager, and if it succeeds, set up the loop to call it again after x seconds.
@param {Boolean} force Force the event call to happen, ignoring the debounce.
@returns {Promise}
Call the event manager and if it succeeds set up the loop to call it again after x seconds . @param { Boolean } force Force the event call to happen ignoring the debounce . @returns { Promise }
function loop(force = false) {
        if (!force && STATE.loopCall && Date.now() - STATE.loopTime < EVENTS_MS.LOOP_DEBOUNCE_MS) {
            return STATE.loopCall;
        }
        stop();
        STATE.loopTime = Date.now();
        return (STATE.loopCall = get()
            .then((data) => {
                STATE.loopCall = undefined;
                STATE.loopTime = 0;
                closeRetryNotification();
                stop();
                STATE.retryIndex = 0;
                start();
                return manage(data);
            })
            .catch((e) => {
                STATE.loopCall = undefined;
                STATE.loopTime = 0;
                stop();
                const { data = {}, status } = e;
                if (data.Code === EVENTS_ID_INVALID) {
                    setEventID(undefined);
                    return start();
                }
                if (status === 0 || status === -1) {
                    showRetryNotification();
                }
                if (STATE.retryIndex < FIBONACCI.length - 1) {
                    STATE.retryIndex++;
                }
                start();
                throw e;
            }));
    }
function loop ( force = false ) { if ( ! force && STATE . loopCall && Date . now ( ) - STATE . loopTime < EVENTS_MS . LOOP_DEBOUNCE_MS ) { return STATE . loopCall ; } stop ( ) ; STATE . loopTime = Date . now ( ) ; return ( STATE . loopCall = get ( ) . then ( ( data ) => { STATE . loopCall = undefined ; STATE . loopTime = 0 ; closeRetryNotification ( ) ; stop ( ) ; STATE . retryIndex = 0 ; start ( ) ; return manage ( data ) ; } ) . catch ( ( e ) => { STATE . loopCall = undefined ; STATE . loopTime = 0 ; stop ( ) ; const { data = { } , status } = e ; if ( data . Code === EVENTS_ID_INVALID ) { setEventID ( undefined ) ; return start ( ) ; } if ( status === 0 || status === - 1 ) { showRetryNotification ( ) ; } if ( STATE . retryIndex < FIBONACCI . length - 1 ) { STATE . retryIndex ++ ; } start ( ) ; throw e ; } ) ) ; }
Call the event manager, and if it succeeds, set up the loop to call it again after x seconds.
Call the event manager and if it succeeds set up the loop to call it again after x seconds .
/*
         * If the interval call is already running AND the elapsed time since the previous pending call is greater than
         * the `loop debounce ms`. Return it.
         *
         * Imagine the following scenario:
         * A user has performed an action and we call the event manager directly. The event call takes 2 seconds to return.
         * In those 2 seconds, before the event call has returned, the user performs another action and we need new data
         * from the event log. In this case it falls through and recalls again.
         *
         * Otherwise, if the application wants to refresh inside the `loop debounce ms` (and we're not forcing a refresh),
         * we return the old call because we don't want to spam the event log either.
         */ // Close any retry notification. /**
                 * If the custom error code is invalid event id, null it and
                 * restart in 30 seconds (to prevent spamming) in case the FE
                 * is doing something wrong.
                 */ // Leaving the notification here for now pending discussion about the behavior. /**
                 * Error handling:
                 * 1) It could have failed because the network is offline, it will either restart from the resurrecter,
                 *    or the user hitting "retry now".
                 * 2) It could have failed because the API is down, so increase the retry index and start the timeout again.
                 */