Imagine that I have some function f()
which should be executed constantly. But I want to set a rate limit for execution, something like "Execute function no more than 10 times in 1 minute". In a code view I think it can have the following interface:
(async () => {
const f = async () => {};
const executor = new Executor({ max: 1, duration: 10000 });
Array(10).fill(null).map(x => executor.addJob(f));
await executor.execute();
})();
I have a few ideas about how to implement this on pure JS, but some implementations are already available? Also, I know that it's possible to implement with some 3-party soft, such as Bull queue and so on, but I need exactly in-process implementation.
Thanks in advance!