import { switchMap, interval, startWith, tap, concatMap, catchError, share, distinctUntilChanged, filter, } from 'rxjs';
import { serializeError } from 'serialize-error';
export const createLoopObservable = (intervalMs, isInitialized$, actionObservable$, beforeCallback) => {
    const source$ = isInitialized$.pipe(distinctUntilChanged(), filter((initialized) => initialized), switchMap(() => {
        return interval(intervalMs).pipe(startWith(0), tap(() => beforeCallback && beforeCallback()), concatMap(() => actionObservable$.pipe(catchError((error) => {
            const serializedError = serializeError(error);
            console.log('Error:', JSON.stringify(serializedError, null, 2));
            throw error;
        }))));
    }));
    return source$.pipe(share());
};
//# sourceMappingURL=rxjs.js.map