Class: EventMachine::Protocols::Zmq2::DealerCb

Inherits:
Dealer show all
Defined in:
lib/em/protocols/zmq2/dealer.rb

Overview

Convinient Dealer class which accepts callback in constructor, which will be called on every incoming message (instead of #receive_message)

Examples:

dealer = EM::Protocols::Zmq2::DealerCb.new do |message|
  puts "Receive message #{message.inspect}"
end
dealer.connect('ipc://rep')
dealer.send_message(['hello','world'])

Instance Method Summary collapse

Methods inherited from Dealer

#flush_queue, #peer_free, #raw_send_message, #send_message

Methods inherited from PreDealer

#choose_peer, #receive_message_and_peer, #send_message

Constructor Details

#initialize(opts = {}, cb = nil, &block) ⇒ DealerCb

Accepts callback as second parameter or block :call-seq:

new(opts) do |message|   end
new(opts, proc{|message| })


140
141
142
143
# File 'lib/em/protocols/zmq2/dealer.rb', line 140

def initialize(opts = {}, cb = nil, &block)
  super opts
  @read_callback = cb || block
end

Instance Method Details

#receive_message(message) ⇒ Object

:nodoc:



145
146
147
# File 'lib/em/protocols/zmq2/dealer.rb', line 145

def receive_message(message) # :nodoc:
  @read_callback.call message
end