Skip to content

Commit

Permalink
close channels when corresponding pipe is closed
Browse files Browse the repository at this point in the history
or an exception occurs
  • Loading branch information
pfitzseb committed Mar 16, 2021
1 parent b347fbf commit a21d5eb
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ function Base.run(x::JSONRPCEndpoint)
else
Base.display_error(stderr, err, bt)
end
finally
close(x.out_msg_queue)
end

x.read_task = @async try
Expand Down Expand Up @@ -143,6 +145,8 @@ function Base.run(x::JSONRPCEndpoint)
else
Base.display_error(stderr, err, bt)
end
finally
close(x.in_msg_queue)
end

x.status = :running
Expand Down Expand Up @@ -233,8 +237,8 @@ function Base.close(endpoint::JSONRPCEndpoint)
flush(endpoint)

endpoint.status = :closed
close(endpoint.in_msg_queue)
close(endpoint.out_msg_queue)
isopen(endpoint.in_msg_queue) && close(endpoint.in_msg_queue)
isopen(endpoint.out_msg_queue) && close(endpoint.out_msg_queue)

fetch(endpoint.write_task)
# TODO we would also like to close the read Task
Expand Down

0 comments on commit a21d5eb

Please sign in to comment.