I read BLE characteristics and send them throught a Flow for the rest of my application to act on it. The BLE characteristics are based on real world events (think of something like a rowing machine). Sometimes, the Flow would emit TONS of values in a very short time frame, sometimes it wouldn't emit for several seconds. I want to limit the "rate" of emission to a maximum of, say, 10 / second. Any higher value is putting the code to unnecessary stress.
Currently, the 2 available APIs won't help me :
.sample() is great but if no value is emitted during the sampling, the flow is stopped. Unreliable in my case.
.debounce() won't produce any intermediate value until the flow is "at rest"
The Shape of the API
The first value would be emitted immediately.
Any subsequent value would be ignored until the duration between the previous emission and current one is greater or equal to the given duration.
Use case
I read BLE characteristics and send them throught a Flow for the rest of my application to act on it. The BLE characteristics are based on real world events (think of something like a rowing machine). Sometimes, the Flow would emit TONS of values in a very short time frame, sometimes it wouldn't emit for several seconds. I want to limit the "rate" of emission to a maximum of, say, 10 / second. Any higher value is putting the code to unnecessary stress.
Currently, the 2 available APIs won't help me :
.sample()
is great but if no value is emitted during the sampling, the flow is stopped. Unreliable in my case..debounce()
won't produce any intermediate value until the flow is "at rest"The Shape of the API
Prior Art
Even if it's not really and argument, Rx has it and it's convenient. https://rxmarbles.com/#throttle