# HG changeset patch # User Tuomo Valkonen # Date 1576697547 -7200 # Node ID a5c1eb932d19c16da2220b37c33b4c04985dd6c3 # Parent 015025cf2a50f30bb98c34c72b8135576f0b6cdb put_unless_closed! diff -r 015025cf2a50 -r a5c1eb932d19 src/Comms.jl --- a/src/Comms.jl Wed Dec 11 18:45:34 2019 +0200 +++ b/src/Comms.jl Wed Dec 18 21:32:27 2019 +0200 @@ -11,7 +11,8 @@ ############## export process_channel, - put_onlylatest! + put_onlylatest!, + put_unless_closed! #################### # Channel iteration @@ -31,8 +32,8 @@ try fn(d) catch ex - error("Exception in process_channel handler. Terminating.\n$(ex)") - throw(ex) + error("Exception in process_channel handler. Terminating.\n") + rethrow(ex) end end end @@ -48,4 +49,21 @@ put!(rc, d) end +############################################ +# Cracefully return false if channel closed +############################################ + +function put_unless_closed!(rc, d) + try + put!(rc, d) + catch ex + if isa(ex, InvalidStateException) && ex.state==:closed + return false + else + rethrow(ex) + end + end + return true +end + end # Module