Search⌘ K
AI Features

Throttling and Buffering

Learn how to control data flow in RxJava when a producer emits items faster than a consumer can handle. This lesson covers throttling operators like sample and throttleFirst, and buffering techniques including buffer and window operators to help you manage backpressure with practical examples.

In addition to backpressure, several useful operators can solve the problem of a fast producer but a slow consumer. These operators allow us to either throttle or buffer items so that a consumer can keep up. Oftentimes, these operators are preferred over backpressure because they are much simpler to work with.

Throttling

Let’s recall the DeviceSensorManager example that we have discussed previously. We saw that the rate at which accelerometer events are emitted is defined by SensorManager.SENSOR_DELAY_NORMAL (that is, about 20 ...