Feature request: latestMap
See original GitHub issueI would love a method to is almost like an .switchMap()
but the big difference is that it should wait until the latest “project” Observable is completed before it starts the latest “project” Observable.
Why?
When you are working with an api that isn’t cancelable and that specific function can only be executed once and have to wait until the callback is executed before you can executed that function/method again and only the lastest value is important.
A use case
When you have a player for instance and want to seek to a current time in playback. Doing multiple seeking at the same time is not desired and in my case also actually crashes the app (smart tv development). To write this code right now is very complicated. We added debounce the seek but this sometimes fails because of slow buffering.
How our code looks like right now
currentTimeChanged$
.debounceTime(1000)
.switchMap(currentTime => Observable
.create((observer) => {
// This api has no cancelation of setCurrentTime and
// can only be executed while not currently seeking.
player.setCurrentTime(currentTime, (error) => {
if (error) return observer.error(error);
observer.complete();
});
})
// The only solution right now is to do something like this
// but sometimes crashes probably because legacy browser and unstable native api.
.retryWhen(error$ => error$.delay(100))
);
Desired code
currentTimeChanged$ // A stream that represent a progress bar
.debounceTime(1000)
// Should subscribe next latest project when idle.
// Should not subscribe latest project until previous project is completed.
.latestMap((currentTime) => {
return Observable.create((observer) => {
// player.setCurrentTime can only be executed while not "running"
player.setCurrentTime(currentTime, () => observer.complete());
});
});
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:9 (4 by maintainers)
@EloB from what I can tell, I think this is
auditMap
– if so, you should be able to achieve something similar viasource.auditTime(1000).exhaustMap((x) => asyncThing(x))
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.