# Is there something equivalent to setInterval() in JS? but in Julia? 

**URL:** <https://discourse.julialang.org/t/is-there-something-equivalent-to-setinterval-in-js-but-in-julia/15577>\
**Category:** General Usage\
**Created:** [September 27, 2018, 8:05pm UTC](https://discourse.julialang.org/t/is-there-something-equivalent-to-setinterval-in-js-but-in-julia/15577 "2018-09-27T20:05:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheOnlyArtz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/theonlyartz/32/12685_2.png) [@TheOnlyArtz](https://discourse.julialang.org/u/TheOnlyArtz)\
**Post date:** [September 27, 2018, 8:05pm UTC](https://discourse.julialang.org/t/is-there-something-equivalent-to-setinterval-in-js-but-in-julia/15577/1 "2018-09-27T20:05:06Z")

</div>

Is there something equivalent to setInterval() in JS? but in Julia?

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [September 27, 2018, 8:25pm UTC](https://discourse.julialang.org/t/is-there-something-equivalent-to-setinterval-in-js-but-in-julia/15577/2 "2018-09-27T20:25:47Z")

</div>

> [@TheOnlyArtz](#):
>
> etInterval()

```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

```

maybe

---

<div class="post-metadata">

**Author:** ![TheOnlyArtz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/theonlyartz/32/12685_2.png) [@TheOnlyArtz](https://discourse.julialang.org/u/TheOnlyArtz)\
**Post date:** [September 27, 2018, 8:46pm UTC](https://discourse.julialang.org/t/is-there-something-equivalent-to-setinterval-in-js-but-in-julia/15577/3 "2018-09-27T20:46:17Z")

</div>

How would I set the interval to repeat exactly every 41 seconds?

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [September 27, 2018, 9:30pm UTC](https://discourse.julialang.org/t/is-there-something-equivalent-to-setinterval-in-js-but-in-julia/15577/4 "2018-09-27T21:30:35Z")

</div>

There is an `interval` keyword argument.

---

<div class="post-metadata">

**Author:** ![TheOnlyArtz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/theonlyartz/32/12685_2.png) [@TheOnlyArtz](https://discourse.julialang.org/u/TheOnlyArtz)\
**Post date:** [September 28, 2018, 5:24am UTC](https://discourse.julialang.org/t/is-there-something-equivalent-to-setinterval-in-js-but-in-julia/15577/5 "2018-09-28T05:24:18Z")

</div>

Yes but why do we need the sleep for? it looks like it extends the time I want.

---

<div class="post-metadata">

**Author:** ![ezgikurt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ezgikurt/32/7017_2.png) [@ezgikurt](https://discourse.julialang.org/u/ezgikurt)\
**Post date:** [June 13, 2019, 5:12pm UTC](https://discourse.julialang.org/t/is-there-something-equivalent-to-setinterval-in-js-but-in-julia/15577/6 "2019-06-13T17:12:02Z")

</div>

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.
