Skip to content

Commit

Permalink
cleanup connection
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubwro committed Jan 28, 2024
1 parent 5de3cd5 commit 7608a59
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
8 changes: 6 additions & 2 deletions src/connection/connection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,16 @@ function stats(connection::Connection)
connection.stats
end

function stats(connection::Connection, sub::Sub)
sub_data = @lock connection.lock get(connection.sub_data, sub.sid, nothing)
function stats(connection::Connection, sid::String)
sub_data = @lock connection.lock get(connection.sub_data, sid, nothing)
isnothing(sub_data) && return
sub_data.stats
end

function stats(connection::Connection, sub::Sub)
stats(connection, sub.sid)
end

function status_change(f, nc::Connection)
while true
st = status(nc)
Expand Down
2 changes: 1 addition & 1 deletion src/connection/drain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function _do_drain(nc::Connection, is_connected; timeout = Timer(nc.drain_timeou
send(nc, Unsub(sid, 0))
end
sleep(nc.drain_poll)
conn_stats = @lock nc.lock nc.stats
conn_stats = stats(nc)
while !is_every_message_handled(conn_stats)
if !isopen(timeout)
@error "Timeout for drain exceeded, not all subs might be drained."
Expand Down
7 changes: 2 additions & 5 deletions src/pubsub/drain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@
### Code:

function drain(connection::Connection, sid::String; timer = Timer(connection.drain_timeout))
sub_data = @lock connection.lock begin
get(connection.sub_data, sid, nothing)
end
if isnothing(sub_data)
sub_stats = stats(connection, sid)
if isnothing(sub_stats)
return # Already drained.
end
sub_stats = sub_data.stats
send(connection, Unsub(sid, 0))
sleep(connection.drain_poll)
while !is_every_message_handled(sub_stats)
Expand Down

0 comments on commit 7608a59

Please sign in to comment.