Is there something ready-to-use for Throttling (sk...
# coroutines
n
Is there something ready-to-use for Throttling (skip some events for a while and handle only last one)? 🤔
m
If your channel has a set capacity, then your senders could use
offer
. If the queue is full, then
offer
will return false and the message is dropped.
n
Ok. And what if I want to get it after some time (e.g. 1000 ms)? Capacity may be 1.
m
You could send it to an actor, and have it forward the message after some delay. But wouldn't that just give you the same problem? It feels like you could just set the capacity to unlimited in that case.
It seems like you want to skip events, but actually not skip them anyway 🙂
n
and have it forward the message after some delay
But it must be canceled if new message received. And it doesn’t seem to be ready-to-use. 🙂
m
Ah, so if the channel is full, you want the last element to be overwritten with the newest event?
d
You should search the channel... this was asked before and a few implementations were proposed, I think 🙂
n
Right. Thanks.
b
This is called a Conflated channel iirc
d
Nope, cause some values might be missed (depending on the state of the sender/receiver), he might want all the values, just at a specific exact interval.
s
It depends. If it is a ‘throttleLast’ type of throttling, a Conflated channel as the throttler in the middle can do the trick. It loops over the incoming values from the producer, sends the value to the next consumer in the pipe-line and then sleeps (delay) for a set number of milliseconds.
A ‘throttleFirst’ type of throttling would require a Channel with a capacity of one.
b
skip some events for a while and handle only last one
that sounds like a ConflatedChannel with an actor that receives after some delay
u
Is this what you want? https://goo.gl/8zvJY2