I would like to integrate a subject into a pipe such that later operators can subscribe to earlier observables.
Context: I want to implement a more sophisticated "debounce" where only certain events can block certain other events. For that, first I want to reimplement "debounce".
This is what I have in mind:
const debounced = myEventStream.pipe(
useSubject(futureEvents => pipe(
flatFilter(
myEvent => race(
interval(10).pipe(map(x => true)),
futureEvents.pipe(/* filter(...), */ map(x => false))
)
)
)),
);
useSubject would provide the following stages of the pipe with an observable of future events. Thus, if flatFilter would exist, events are not filtered, if the interval triggers first, but filtered, if a newer event comes in.
Is such an useSubject reasonable - can it work? Does such an useSubject already exists?