Throttling Events

Let's see some use cases of both the throttle operator and the debounce function.

Sometimes a debounce is more complicated than what we really need.

throttle operator

The throttle operator acts as a time-based filter.

Filtering values using throttle

After it allows a value through, it won’t allow a new value, until a preset amount of time has passed. All other values are thrown away.

This can be useful when you connect to a noisy WebSocket that sends a lot more data than you need.

For instance, you might be building a dashboard to keep the ops folks informed about all of their systems, and the monitoring backend sends updates on CPU usage several dozen times a second.

DOM updates are slow, and that level of granularity isn’t helpful anyway. Here, we just update the page every half-second.

Get hands-on with 1200+ tech skills courses.