for some reason i was worried, quite anxious, about writing a timer in such a simple way.
but after doing a quick calculation, i can see fifteen minutes is only 900 seconds.
this gives me quite a bit of relief.
i think a simple FOR loop can be written:
FOR H=1 TO 900
REM DUTIES PERFORMED EVERY SECOND
DELAY 1000
NEXT H
REM WE FALL INTO THIS CODE HERE
REM DUTIES PERFORMED EVERY 15 MIN
- replies
- 1
- announces
- 0
- likes
- 0
@uwu@social.solarpunk.au nope! if you run this it will start to drift because execution time isn't taken in to account in that DELAY 1000.
a slightly better pattern is:
passed = time.now
if (time.now - 1000 > passed) {
passed = time.now
do stuff
} else {
sleep 0.01 /* NOP */
}
but this has a problem if the task takes longer than you intend on delaying -- it will immediately trigger again.@purple i'm not that concerned about execution drift--is that the only problem this code will have?