Class: Stomper::ReceiptManager
- Inherits:
-
Object
- Object
- Stomper::ReceiptManager
- Defined in:
- lib/stomper/receipt_manager.rb
Overview
Manages receipt handling for a Connection
Instance Method Summary collapse
-
#add(r_id, callback) ⇒ self
Adds a callback handler for a RECEIPT frame that matches the supplied receipt ID.
-
#clear ⇒ Object
Remove all receipt handlers.
-
#initialize(connection) ⇒ ReceiptManager
constructor
Creates a new receipt handler for the supplied connection.
Constructor Details
#initialize(connection) ⇒ ReceiptManager
Creates a new receipt handler for the supplied connection
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/stomper/receipt_manager.rb', line 7 def initialize(connection) @mon = ::Monitor.new @callbacks = {} connection.before_disconnect do |d, con| @close_on = d[:receipt] if d[:receipt] end connection.on_receipt do |r, con| dispatch(r) connection.close if r[:'receipt-id'] == @close_on end end |
Instance Method Details
#add(r_id, callback) ⇒ self
Adds a callback handler for a RECEIPT frame that matches the supplied receipt ID.
25 26 27 28 |
# File 'lib/stomper/receipt_manager.rb', line 25 def add(r_id, callback) @mon.synchronize { @callbacks[r_id] = callback } self end |
#clear ⇒ Object
Remove all receipt handlers.
31 32 33 |
# File 'lib/stomper/receipt_manager.rb', line 31 def clear @mon.synchronize { @callbacks.clear } end |