Skip to content

Commit

Permalink
Merge pull request #3764 from amitmurthy/amitm/timedwait
Browse files Browse the repository at this point in the history
Added @timedwait
  • Loading branch information
amitmurthy committed Jul 19, 2013
2 parents 13cfbeb + eda953a commit 0804aca
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
3 changes: 2 additions & 1 deletion base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1258,4 +1258,5 @@ export
@sprintf,
@deprecate,
@boundscheck,
@inbounds
@inbounds,
@timedwait
34 changes: 34 additions & 0 deletions base/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,37 @@ end
# Conditional usage of packages and modules
usingmodule(names::Symbol...) = eval(current_module(), Expr(:toplevel, Expr(:using, names...)))
usingmodule(names::String) = usingmodule([symbol(name) for name in split(names,".")]...)


macro timedwait(ex, wait_secs, poll_interval)
quote
start = time()
done = RemoteRef()
function timercb(aw, status)
try
if $(esc(ex))
put(done, :ok)
elseif (time() - start) > $(wait_secs)
put(done, :timed_out)
elseif status != 0
put(done, :error)
end
catch e
put(done, :error)
stop_timer(aw)
end
end

if !$(esc(ex))
t = TimeoutAsyncWork(timercb)
start_timer(t, $(poll_interval), $(poll_interval))
ret = fetch(done)
stop_timer(t)
else
ret = :ok
end
ret
end
end


0 comments on commit 0804aca

Please sign in to comment.