Class: Rabbit::Publishing::ChannelsPool

Inherits:
Object
  • Object
show all
Defined in:
lib/rabbit/publishing/channels_pool.rb

Defined Under Namespace

Classes: BaseQueue, ConfirmQueue

Instance Method Summary collapse

Constructor Details

#initialize(session) ⇒ ChannelsPool

Returns a new instance of ChannelsPool.



56
57
58
59
60
61
62
63
# File 'lib/rabbit/publishing/channels_pool.rb', line 56

def initialize(session)
  max_size = session.channel_max

  @pools = {
    true => ConfirmQueue.new(session, max_size / 2),
    false => BaseQueue.new(session, max_size / 2),
  }.freeze
end

Instance Method Details

#with_channel(confirm) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/rabbit/publishing/channels_pool.rb', line 65

def with_channel(confirm)
  pool = @pools[confirm]
  ch = pool.deq
  yield ch
ensure
  pool.enq ch
end