/*
 * Copyright (c) 2019 Robert Bosch Manufacturing Solutions GmbH, Germany. All rights reserved.
 */

import { merge, MonoTypeOperatorFunction, of, pipe, timer } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';

/**
 * Periodic timer reseted by every emission.
 * @param delayValue Delay to wait until emitting another value in ms.
 */
export function periodicRepeat<T>(delayValue: number): MonoTypeOperatorFunction<T> {
  return pipe(switchMap((value) => merge(of(value), timer(delayValue, delayValue).pipe(map(() => value)))));
}
