How does throttleTime operator's config parameter work? (ThrottleConfig)

前端 未结 1 1563
余生分开走
余生分开走 2020-12-19 05:52

I have read the throttleTime documentation, but I don\'t get the operator fully.

I know how throttleTime(1000) works. After an event arrives it will ski

相关标签:
1条回答
  • 2020-12-19 06:41

    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.

    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

    { leading: true, trailing: false }
    
    source:               --0----1----2----3----4----5----6----7----8-- 
    throttle interval:    --[~~~~~~~~~~~~~~~~~]-[~~~~~~~~~~~~~~~~~]-[~~ 
    output:               --0-------------------4-------------------8--
    
    { leading: false, trailing: true }
    
    source:               --0----1----2----3----4----5----6----7----8-- 
    throttle interval:    --[~~~~~~~~~~~~~~~~~]-[~~~~~~~~~~~~~~~~~]-[~~ 
    output:               --------------------3-------------------7----
    
    { leading: true, trailing: true }
    
    source:               --0----1----2----3----4----5----6----7----8-- 
    throttle interval:    --[~~~~~~~~~~~~~~~~~]-[~~~~~~~~~~~~~~~~~]-[~~  
    output:               --0-----------------3-4-----------------7-8--
    
    { leading: false, trailing: false }
    
    source:               --0----1----2----3----4----5----6----7----8--
    throttle interval:    --[~~~~~~~~~~~~~~~~~]-[~~~~~~~~~~~~~~~~~]-[~~
    output:               ---------------------------------------------
    
    0 讨论(0)
提交回复
热议问题