# Where to set a timeout on a task

**URL:** <https://discourse.julialang.org/t/where-to-set-a-timeout-on-a-task/93579>\
**Category:** New to Julia\
**Tags:** question, task\
**Created:** [January 26, 2023, 3:24pm UTC](https://discourse.julialang.org/t/where-to-set-a-timeout-on-a-task/93579 "2023-01-26T15:24:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![1153dent](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/1153dent/32/43968_2.png) [@1153dent](https://discourse.julialang.org/u/1153dent)\
**Post date:** [January 26, 2023, 3:24pm UTC](https://discourse.julialang.org/t/where-to-set-a-timeout-on-a-task/93579/1 "2023-01-26T15:24:17Z")

</div>

hi there

Has anyone got an effective approach to setting a timeout on multiple async calls.

So if I send out 10 calls each with it’s own id and timer. I would handle the callback in a wrapper.

Can I determine WHICH timer blew from the call id or is there a better way?

**an example usecase**

send 10 requests to a weather service each asking for a realtime data on a different city.

set up a wrapper to handle the returning data stream

if a datastream does not start then retry original a call unless number of retries exceeded for that call.

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [January 28, 2023, 3:45pm UTC](https://discourse.julialang.org/t/where-to-set-a-timeout-on-a-task/93579/2 "2023-01-28T15:45:42Z")

</div>

I’m not sure it’s supported in general, but at least see this thread (with a macro to do it, I didn’t read carefully, may only work in some cases, or info there outdated?):

> [@Help writing a timeout macro](https://discourse.julialang.org/t/help-writing-a-timeout-macro/16591):
>
> I have a function that can either execute quickly or take a very long time. I want to kill the function after a certain amount of time so I can fall back on a more reliable method. I should be able to do this using a macro. The problem is I am a bit out of my depth. I took info from [here](https://www.reddit.com/r/Julia/comments/78it4f/execute_a_function_with_a_timeout_time_limit/) and [here](https://stackoverflow.com/questions/51264467/timeout-function-in-julia) and this is what I have so far macro timeout(time,f) quote t = Task($f) schedule(t) Timer(x -\> (istaskdone(t) || Base.throwto(t,InterruptException())),$time) t e…

It seems to be supported in some other languages (so maybe reasonable to think should work in all cases in Julia?):

> <https://stackoverflow.com/questions/4238345/asynchronously-wait-for-taskt-to-complete-with-timeout>

---

<div class="post-metadata">

**Author:** ![1153dent](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/1153dent/32/43968_2.png) [@1153dent](https://discourse.julialang.org/u/1153dent)\
**Post date:** [January 28, 2023, 4:40pm UTC](https://discourse.julialang.org/t/where-to-set-a-timeout-on-a-task/93579/3 "2023-01-28T16:40:48Z")

</div>

THANK YOU @Palli !!! This was the clincher for me from [hhaensel](https://discourse.julialang.org/t/help-writing-a-timeout-macro/16591/7)

Really helped. Thanks both  
dent
