api3dao / commons

Common utilities, modules and configurations used in API3 projects
MIT License
0 stars 2 forks source link

Create runInLoop function #104

Closed Siegrift closed 2 weeks ago

Siegrift commented 1 month ago

We are using async loops design pattern quite a lot and many repositories define it's own implementation. Note, that we don't like the setInterval function, because it's possible that it will result in overlapping calls, which is often what we want to avoid. A direct counterargument is that we don't want the loop to be "stuck".

A reasonable workaround is to have a while loop, which runs the function and waits the remaining time. If the execution exceeds the allowed periodicity it issues a warning. If it exceeds the periodicity by some multiple (e.g. 10) it force starts a new callback and issues the error.

Look at the implementation in OEV Auctioneer. A similar one can be created here with the following features:

Siegrift commented 1 month ago

It would also be nice to: