Skip to content

Commit

Permalink
Yield when closing consumers and channels
Browse files Browse the repository at this point in the history
  • Loading branch information
spuun committed Feb 13, 2025
1 parent 822c7ba commit 7538965
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/lavinmq/amqp/channel.cr
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,10 @@ module LavinMQ

def close
@running = false
@consumers.each &.close
@consumers.each_with_index(1) do |consumer, i|
consumer.close
Fiber.yield if (i % 128) == 0
end
@consumers.clear
if drc = @direct_reply_consumer
@client.vhost.direct_reply_consumers.delete(drc)
Expand Down
6 changes: 5 additions & 1 deletion src/lavinmq/amqp/client.cr
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,11 @@ module LavinMQ

private def cleanup
@running = false
@channels.each_value &.close
i = 0u32
@channels.each_value do |ch|
ch.close
Fiber.yield if (i &+= 1) % 512 == 0
end
@channels.clear
@exclusive_queues.each(&.close)
@exclusive_queues.clear
Expand Down

0 comments on commit 7538965

Please sign in to comment.