I am trying to achieve the following behavior:
I have a source observable that emits every second.
I am trying to ignore values for some period(10 seconds) of time if another observable(mySubject) emitted value.
This is what I came for:
this.source.pipe(
takeUntil(this.mySubject),
repeatWhen((observable) => observable.pipe(delay(10000))),
tap((x) => console.log(x)),
).subscribe();
Now it's stoping the emitting of the source for 10 seconds on every mySubject emission.
The problem is that I need it if another emission of mySubject to reset the "count" of the 10 seconds and ignore for another 10 seconds without emitting anything meanwhile.
How can I achieve this?
I'm afraid this requires a little more complicated solution:
const ignore$ = this.mySubject.pipe(
switchMap(() => merge(of(true), of(false).pipe(delay(10 * 1000)))),
);
this.source.pipe(
withLatestFrom(ignore$),
filter(([value, ignore]) => !ignore),
map(([value]) => value),
).subscribe(...);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With