The sample operator

The groupBy(), buffer(), and window() operators aggregate inputs and consolidate them into chunks, based on their size, time period, or condition. They are not aimed at skipping events. At times, you may be required to skip events and listen to a particular event during a given time interval. This is often required for fast, non-changing events, such as user clicks. In such a situation, we need to throttle the flow and pick data selectively.

The sample() operator allows us to accomplish this throttling. It takes a time period and listens to events published during that time period. It then publishes the last event that happened during the time period. This is depicted in the following diagram:

Let's try to add a delay ...

Get Hands-On Reactive Programming with Reactor now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.