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:
Accept a log message that is printed for the warning/error
Support min/max waiting time. The idea is that we have a long running, repeated task but want to execute it as fast as possible. It would be convenient to specify a fixed min/max wait time. E.g. searcher bot use case.
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: