Skip to content

Commit

Permalink
Fix #113 and add Inf timeout option (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
samoconnor authored and quinnj committed Nov 15, 2017
1 parent cce51ca commit 779fe74
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,19 @@ checking if `expr` has finished executing (short for polling interval).
"""
macro timeout(t, expr, then, pollint=0.01)
return quote
tm = Float64($(esc(t)))
start = time()
tsk = @async $(esc(expr))
while !istaskdone(tsk) && (time() - start < tm)
sleep($pollint)
if $(esc(t)) == Inf
$(esc(expr))
else
tm = Float64($(esc(t)))
start = time()
tsk = @async $(esc(expr))
yield()
while !istaskdone(tsk) && (time() - start < tm)
sleep($pollint)
end
istaskdone(tsk) || $(esc(then))
wait(tsk)
end
istaskdone(tsk) || $(esc(then))
tsk.result
end
end

Expand Down

0 comments on commit 779fe74

Please sign in to comment.