How can I get RXJS throttleTime to enable both leading and trailing while preventing requests in quick succession

129 Views Asked by At

I basically want to use thottleTime except I don't want to ever enable 2 notifications to be run in quick succession. It seems that throttletime basically resets its timer after it completes a "trailing" notificaiton.

So for source notifications (where each character is separated by 1000ms)

-AB---C----

So assuming usage thottleTime(3000, asyncScheduler, { leading: true, trailing: true }), this will push notifications:

-A---BC----

(aka it fires the leading 'A', and the trailing 'B' 3 seconds later which is what I want, however it immediately fires the next 'C' as it is a new leading notification.

What I really want is:

-A---B---C-

In summary, how can I get an operator that:

  1. Immediately fires on first notification
  2. Waits X amount of time minimum before firing the next noficiation.
  3. ONLY immediately fires a third notification if it is at least X amount of time after the 2nd.

I have seen various other options on SO that meet (1) and (2), but none that meet (3) also.

0

There are 0 best solutions below