I have an observable stream which emits numbers, I want another stream that emits all 1's that are not closely followed by a 2 (within say 200ms), so for example from this source stream:
(every character is 100ms)
1...12...112...11121...
The result should be:
..1.......1.....11...1.
How would I do that using rxjs@^6.6.7
?
Based on @martin's answer:
when a 1 is emitted,
https://stackblitz.com/edit/rxjs-ihyznt?devtoolsheight=66&file=index.ts
source
.pipe(
filter(value => value != 2),
mergeMap(value =>
source.pipe(
first(),
filter(v => v != 2),
map(_ => value),
timeout(200),
catchError(_ => of(value))
)
)
)
.subscribe(value => console.log(value));