Skip to content

Commit

Permalink
Merge pull request #111 from rdeits/rd/wait
Browse files Browse the repository at this point in the history
work-around for race condition in `wait()`
  • Loading branch information
rdeits authored Jul 10, 2019
2 parents 66a3c1d + 0bfa9a5 commit 5fe7b9c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/visualizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,19 @@ function send(c::CoreVisualizer, cmd::AbstractCommand)
nothing
end

Base.wait(c::CoreVisualizer) = WebIO.ensure_connection(c.scope.pool)
function Base.wait(c::CoreVisualizer)
pool = c.scope.pool
while true
while isready(pool.new_connections)
push!(pool.connections, take!(pool.new_connections))
end
if !isempty(pool.connections)
break
else
sleep(0.25)
end
end
end

"""
vis = Visualizer()
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ using MeshIO, FileIO
include("visualizer.jl")
include("notebook.jl")
include("scenes.jl")
include("wait.jl")
end

sleep(10)
Expand Down
20 changes: 20 additions & 0 deletions test/wait.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# https://github.com/rdeits/MeshCat.jl/pull/99#issuecomment-509067108

@testset "wait" begin
@testset "with setobject" begin
vis = Visualizer()
setobject!(vis, Triad(1.0))
if !haskey(ENV, "CI")
open(vis)
wait(vis)
end
end

@testset "without setobject" begin
vis = Visualizer()
if !haskey(ENV, "CI")
open(vis)
wait(vis)
end
end
end

0 comments on commit 5fe7b9c

Please sign in to comment.