Is there something equivalent to setInterval() in JS? but in Julia?
help?> Timer Timer(callback::Function, delay; interval = 0) Create a timer that wakes up tasks waiting for it (by calling wait on the timer object) and calls the function callback. Waiting tasks are woken and the function callback is called after an initial delay of delay seconds, and then repeating with the given interval in seconds. If interval is equal to 0, the timer is only triggered once. The function callback is called with a single argument, the timer itself. When the timer is closed (by close waiting tasks are woken with an error. Use isopen to check whether a timer is still active. Examples ≡≡≡≡≡≡≡≡≡≡ Here the first number is printed after a delay of two seconds, then the following numbers are printed quickly. julia> begin i = 0 cb(timer) = (global i += 1; println(i)) t = Timer(cb, 2, interval = 0.2) wait(t) sleep(0.5) close(t) end 1 2 3
How would I set the interval to repeat exactly every 41 seconds?
There is an
interval keyword argument.
Yes but why do we need the sleep for? it looks like it extends the time I want.
Hi, did you figure this out? the Timer() worked fine for me in some old code in Julia 0.5 but now can’t get it to work for v1.0.