Proposal: new operator exhaustMap with buffer #6461
Etienne-M
started this conversation in
Ideas / Feature request
Replies: 3 comments 4 replies
-
Moved to the discussions with specific category. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Does https://rxjs-dev.firebaseapp.com/api/operators/takeLast solve your problem if it is applied on the inner observable? |
Beta Was this translation helpful? Give feedback.
2 replies
-
this should be similar to the removed so something like this: function inspectMap<T, R>(project: (value: T, index: number) => ObservableInput<R>): OperatorFunction<T, R> {
return (source$) => {
const subject$ = new BehaviorSubject(true);
return source$.pipe(
audit(() => subject$.pipe(filter(Boolean))),
tap(() => void subject$.next(false)),
map(project),
map(from),
mergeMap(tap({ complete: () => void subject$.next(true) })),
);
};
} |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
This is an improvement proposal based on a use-case I am often facing and can't easily address with the current operators.
Description
It's the same thing as
exhaustMap
, except that it replays the last missed event on completion of the inner observable. OrconcatMap
, but with a buffer size of 1.Context
One of the basic use of RxJS that I have in my projects is the following: there is some state in my application that I am observing and for which I want to perform some side effects. In other words, my app is a big state machine and depending on its state, I want to do some actions.
How do you handle backpressure in those cases?
mergeMap
does not make sense,switchMap
would trigger way more operations than necessary,concatMap
would exacerbate the problem. The one that makes the most sense isexhaustMap
, but there is a problem: you end up being late on the state machine. What I am suggesting is an alternate operator that would replay the last event upon completion of the inner observable. Translated for this use-case, it would wait for the async operation to finish, then make sure to handle the most up-to-date state.Implementation
I have everything already coded, I would love to contribute it back since I think it might be a use case other people have.
Beta Was this translation helpful? Give feedback.
All reactions