Timed loop

We have timedwait in Base (but this polls) or you could follow the following pattern:

cond = Condition()
Timer(x->notify(cond), max_time)
t = @async begin
    # do stuff
    notify(cond)
end
wait(cond)
t.state == :done ? fetch(t) : :timeout

see also: How to wait on a condition for tasks

Better yet to put it in a function! Then you can return a value or a timeout.

2 Likes