How does throttleTime operator's config parameter work? (ThrottleConfig)
throttleTime
will start a new throttle interval (a time period in which no items will be emitted) when it receives a new value and isn't already throttled. The length of this throttle interval is determined by the duration you supply.
leading
and trailing
specify whether an item should be emitted at the beginning or end of a throttle interval.
leading:
Emit the item that starts a new throttle interval at the beginning of the throttle interval.
trailing:
Emit the last item received from the source at the end of a throttle interval.
Visualisation
throttleTime(12 ticks, async, { leading: true, trailing: false })
source: --0--1-----2--3----4--5-6---7------------8-------9--------
throttle interval: --[~~~~~~~~~~~~]---[~~~~~~~~~~~~]--------[~~~~~~~~~~~~]---
output: --0----------------4---------------------8----------------
throttleTime(12 ticks, async, { leading: false, trailing: true })
source: --0--1-----2--3----4--5-6---7------------8-------9--------
throttle interval: --[~~~~~~~~~~~~]---[~~~~~~~~~~~~]--------[~~~~~~~~~~~~]---
output: ---------------3----------------7---------------------9---
throttleTime(12 ticks, async, { leading: true, trailing: true })
source: --0--1-----2--3----4--5-6---7------------8-------9--------
throttle interval: --[~~~~~~~~~~~~]---[~~~~~~~~~~~~]--------[~~~~~~~~~~~~]---
output: --0------------3---4------------7--------8------------9---
throttleTime(12 ticks, async, { leading: false, trailing: false })
source: --0--1-----2--3----4--5-6---7------------8-------9--------
throttle interval: --[~~~~~~~~~~~~]---[~~~~~~~~~~~~]--------[~~~~~~~~~~~~]---
output: ----------------------------------------------------------