The sample() operator can also be used to mitigate the problem of backpressure in a lossy way. It lets you receive data from the observable at every given interval.
The sample() operator has the following signature:
The first parameter is mandatory and the second is optional:
- interval: This is the time interval, in milliseconds, between the emission of data. This parameter can also be an observable. In this case, this observable will be used to sample the data.
- scheduler: This is used to propagate the data
Let's use the same example from the throttle() method (using the interval() method to create an Observable) and change it to use the sample() method:
Rx.Observable .interval(50) ...