Currently, I am in the process of developing an Angular application that utilizes an API provided by a social network. Unfortunately, this API has a restriction of only allowing 5 API calls per second.
The typical solution to this limitation involves implementing custom logic to track and queue requests based on the restrictions. If a 6th request is made within one second, it will be delayed until the next allowable time slot.
However, I am interested in exploring more elegant solutions using RxJs.
For example, I have considered setting the debounceTime for the Observable, as shown in the code snippet below. Yet, this approach presents limitations, as it prevents making multiple requests with intervals shorter than 200ms between them.
this.searchControl.valueChanges
.debounceTime(200) // 200ms ~ 5 requests per second
.switchMap(search => this.api.searchPeople(search))
Are there any techniques within RxJs that can help restrict the number of emits per interval and queue excess requests when they are being sent too frequently?