Skip to content

Commit

Permalink
try-catch to prevent closed channel error (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
bclyons12 authored Jul 26, 2024
1 parent d63c58c commit ff877b7
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -192,18 +192,28 @@ function readg(gfile; set_time=nothing)
zlim = [0.0]
end

for i 1:3
local rhovn
try
for i 1:3
if !eof(f)
xdum = take!(token)
end
end
if !eof(f)
rhovn = read_array(token,nw)
else
rhovn = zeros(nw)
end
if !eof(f)
xdum = take!(token)
end
end
if !eof(f)
rhovn = read_array(token,nw)
else
rhovn = zeros(nw)
end
if !eof(f)
xdum = take!(token)
catch e
if isa(e, InvalidStateException)
# InvalidStateException when Channel is closed
rhovn = zeros(nw)
else
rethrow(e)
end
end

close(f)
Expand Down

0 comments on commit ff877b7

Please sign in to comment.