ThrottleTime with immediate output but all events must be n ms apart
@benlesh is already working on this.
Since Jul 29, 2020.
- Dominant language
- TypeScript
- Stars
- 31.7k
- Forks
- 3k
- PR merge metrics
- No merged PRs in 30d
Description
Feature Request
Is your feature request related to a problem? Please describe.
With the current throttleTime behavior with config {leading: true, trailing: true}, events are not guaranteed n ms apart. For example:
const observable = cold('-abcdef-----abcdef|');
const throttled = observable.pipe(
throttleTime(time('---|'), getTestScheduler(), {leading: true, trailing: true}));
getTestScheduler().expectObservable(throttled).toBe('-a--de--f---a--de-(f|)');
Describe the solution you'd like
I want all events to be at least n ms apart. Specifically:
const observable = cold('-abcdef-----abcdef|');
const throttled = observable.pipe(
throttleTime(time('---|'), getTestScheduler(), someFooConfig));
getTestScheduler().expectObservable(throttled).toBe('-a--d--f----a--d--(f|)');
Describe alternatives you've considered
I'm currently using throttleTime with {leading: true, trailing: true}, but that's not ideal since my RPCs are not always n ms apart (causing them being throttled from the server). The default config {leading: true, trailing: false} does not cut it because some trailing events are missing. The config {leading: false, trailing: true} does not cut it either because I'd like to process the event immediately if possible.
(If this is new operator request) describe reason it should be core operator
This can be achieved in the user-land module by just clone the throttleTime code and does the fix myself in my code, but that's not very elegant.
Additional context
This feature seems to be the one requested in https://github.com/ReactiveX/rxjs/issues/1625 , but the fix did not achieve that objective.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.