I created a class which sets up a pausable rxjs observable on an interval:
export class RepeatingServiceCall {
private paused = false;
private o
You can achieve the behavior you are describing with the following snippet:
const delay = 1000;
const playing = new BehaviorSubject(false);
const observable = playing.pipe(
switchMap(e => !!e ? interval(delay).pipe(startWith('start')) : never())
);
observable.subscribe(e => console.log(e));
// play:
playing.next(true);
// pause:
playing.next(false);
playing Observable emits true, the switchMap operator will return a new interval Observable.startWith operator to emit an event immediately when unpausing.true.StackBlitz Example