Reputation: 7609
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
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