David Alsh
David Alsh

Reputation: 7609

If an event is fired during throttleTime's timeout, replay last event after timeout completes and begin timeout again

What I'd like to see is this output:

|---0--0--0-----0---------------> Events
|---0-------0-------0-----------> Output

I supply a duration, the stream allows the first event through, waits the duration amount. If an event was triggered during the timeout period, emit and start the timeout again.

The values don't matter in my case, only knowing events happened.

How would I achieve this with RXJS? I started with throttleTime, but throttleTime doesn't emit the trailing event when its timeout finishes.

subject
    .pipe(
        throttleTime(5000)
    )
    .subscribe(
        event => action()
    )

Upvotes: 2

Views: 129

Answers (1)

Jesse
Jesse

Reputation: 2599

Check out the docs for throttleTime. You can pass in an optional config and specify leading / trailing behavior. What you ran into was this:

config:

Optional. Default is defaultThrottleConfig.

a configuration object to define leading and trailing behavior. Defaults to { 
leading: true, trailing: false }.

Upvotes: 1

Related Questions