Thoughts:
The JavaScript idiomatic way of doing EVERY_N_MILLISECONDS()
is to use an interval (which doesn’t exist in PB yet):
setInterval(function() {
// do stuff here
}, 500) //every 500 ms
One problem here is that using a unit of milliseconds limits the range to about 32 seconds due to the fixed point value range in PB. It would be useful even with that limit, and a variant that worked in seconds would come in handy. I don’t think that would be a problem for these cases.
It also calls the timeout function asynchronously (in the main event loop after other code has returned), whereas the EVERY_N_MILLISECONDS()
macro executes it in-line. I suspect for most things the timing wouldn’t matter.
Here’s an implementation of setTimeout (in seconds), which is the one-shot version. It’s not too dissimilar to your implementation, @pixie.