# How to build a setInterval-like task?

**URL:** <https://discourse.julialang.org/t/how-to-build-a-setinterval-like-task/79595>\
**Category:** General Usage\
**Tags:** task\
**Created:** [April 17, 2022, 9:02am UTC](https://discourse.julialang.org/t/how-to-build-a-setinterval-like-task/79595 "2022-04-17T09:02:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rratic](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rratic/32/24917_2.png) [@Rratic](https://discourse.julialang.org/u/Rratic)\
**Post date:** [April 17, 2022, 9:02am UTC](https://discourse.julialang.org/t/how-to-build-a-setinterval-like-task/79595/1 "2022-04-17T09:02:44Z")

</div>

This is my idea

```nohighlight
task=@task begin
while true
sleep(1)
foo()
if should_end
    # ?
end
end
end

```

But

1. are there any simple ways to contact other than using `global should_end`?
2. how to end the task from inside the expression?

[stackoverflow sync](https://stackoverflow.com/questions/71901528/how-to-build-a-setinterval-like-task)

P.S.  
The problem is solved in an answer in stackoverflow.

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [April 17, 2022, 1:30pm UTC](https://discourse.julialang.org/t/how-to-build-a-setinterval-like-task/79595/2 "2022-04-17T13:30:09Z")

</div>

You mean repeatedly calling a function until some condition is met? You may want to look into [`Timer`](https://docs.julialang.org/en/v1/base/base/#Base.Timer-Tuple%7BFunction,%20Real%7D).
