Skip to content

Commit 25ece66

Browse files
committed
keep track of async and wait for gui
1 parent fd80619 commit 25ece66

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

NetworkDynamicsInspector/src/appstate.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ struct AppState
4040
active_tsplot::Observable{String}
4141
graphplot::GraphPlot
4242
tsplots::Observable{OrderedDict{String, TimeseriesPlot}}
43+
_plotqueue::Channel{Task}
4344
end
4445
function AppState(sol::SciMLBase.AbstractODESolution)
4546
t = sol.t[begin]
@@ -50,7 +51,8 @@ function AppState(sol::SciMLBase.AbstractODESolution)
5051
"ts-1" => TimeseriesPlot(),
5152
)
5253
active_tsplot = "ts-1"
53-
AppState(sol, t, tmin, tmax, active_tsplot, graphplot, tsplots)
54+
_plotqueue = Channel{Task}(Inf)
55+
AppState(sol, t, tmin, tmax, active_tsplot, graphplot, tsplots, _plotqueue)
5456
end
5557

5658
function free_ts_key()

NetworkDynamicsInspector/src/timeseries.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ function timeseries_card(app, key, session)
358358
last_autolimits = Ref((eltype(valid_idxs)(), tsplot.rel[]))
359359
# plot the thing
360360
onany(data, replot; update=true) do _dat, _
361-
@async begin
361+
task = @async begin
362362
try
363363
empty!(ax)
364364
vlines!(ax.scene, app.t; color=:black)
@@ -381,6 +381,7 @@ function timeseries_card(app, key, session)
381381
@error "Plotting failed" e
382382
end
383383
end
384+
push!(app._plotqueue, task)
384385
nothing
385386
end |> track_obsf
386387

NetworkDynamicsInspector/src/utils.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,12 @@ function download_assets()
141141
download(url, joinpath(ASSETS, name))
142142
end
143143
end
144+
145+
function wait_for()
146+
isnothing(APPSTATE[]) && return
147+
queue = APPSTATE[]._plotqueue
148+
while !isempty(queue)
149+
wait(take!(queue))
150+
end
151+
nothing
152+
end

0 commit comments

Comments
 (0)