How can a function rate-limit its calls? The calls should not be discarded if too frequent, but rather be queued up and spaced out in time, X milliseconds apart. I've looked at throttle and debounce, but they discard calls instead of queuing them up to be run in the future.
Any better solution than a queue with a process()
method set on an X millisecond interval? Are there such standard implementations in JS frameworks? I've looked at underscore.js so far - nothing.
setInterval
was to process the queue, like in this example. – StigmasetInterval
, when time to process exceeds the delay, you end up in an environment where the second tries to happen before the first finishes, which makes both slower, so the third tries to happen before the second finishes, and maybe the first. Ultimately, then+1
th starts to happen before then
th andn-1
th have finished, and then all hell breaks loose – Bourke