src/Visualise.jl

changeset 11
f1bbdf68f35b
parent 9
1cffd3d07fe2
child 13
bda471ea9d67
--- a/src/Visualise.jl	Thu Nov 21 22:17:52 2019 -0500
+++ b/src/Visualise.jl	Thu Dec 05 16:50:11 2019 +0200
@@ -5,7 +5,6 @@
 module Visualise
 
 using Printf
-using Distributed
 using FileIO
 using Setfield
 using Images, Plots, Measures
@@ -39,8 +38,8 @@
 end
 
 struct State
-    vis :: Union{Distributed.RemoteChannel,Bool,Nothing}
-    visproc :: Union{Nothing,Future}
+    vis :: Union{Channel,Bool,Nothing}
+    visproc :: Union{Nothing,Task}
     start_time :: Union{Real,Nothing}
     wasted_time :: Real
     log :: LinkedList{LogEntry}
@@ -82,14 +81,14 @@
     display(plot([plt(imgs[i]) for i =1:length(imgs)]..., reuse=true, margin=0mm))
 end
 
-function visualise(rc_or_vis, imgs)
-    if isa(rc_or_vis, RemoteChannel)
-        rc = rc_or_vis
+function visualise(channel_or_toggle, imgs)
+    if isa(channel_or_toggle, Channel)
+        rc = channel_or_toggle
         while isready(rc)
             take!(rc)
         end
         put!(rc, imgs)
-    elseif isa(rc_or_vis, Bool) && rc_or_vis
+    elseif isa(channel_or_toggle, Bool) && channel_or_toggle
         do_visualise(imgs)
     end
 end
@@ -164,8 +163,8 @@
 function initialise_visualisation(visualise; iterator=iterate_visualise)
     # Create visualisation
     if visualise
-        rc = RemoteChannel()
-        visproc = @spawn bg_visualise(rc)
+        rc = Channel()
+        visproc = Threads.@spawn bg_visualise(rc)
         vis =rc
         #vis = true
 
@@ -182,9 +181,9 @@
 end
 
 function finalise_visualisation(st)
-    if isa(st.rc, RemoteChannel)
+    if isa(st.vis, Channel)
         # Tell subprocess to finish, and wait
-        put!(st.rc, nothing)
+        put!(st.vis, nothing)
         wait(st.visproc)
     end
 end

mercurial