Minimum Rate
Flow.rateMinimum ensures that a function gets called at a minimum rate.
The basic usage looks like:
On line 1 we invoke rateMinimum
, getting back a function, rm
to call with a value. We’d call this whenever we have a value to process. The value gets passed to the whatToCall
function provided on line 3.
Now, if we don’t call rm
at least every second, rateMinimum
will call the fallback function (line 6) to generate a value and provides it to whatToCall
.
In other words, the whatToCall
function gets called at least every second, with either a value that’s passed in when we invoke rm
, or using a generated fallback value.
Practical case
Let’s say for example you want to do something based on the speed of the pointer movement. One way to calculate speed is to recalculate based on total travel and current elapsed time. You can easily use the pointermove
event to have a function called when the pointer moves, but there’s not an event for when the pointer is not moving.