Class: EventMachine::Protocols::Zmq2::Sub
- Inherits:
-
Socket
- Object
- Socket
- EventMachine::Protocols::Zmq2::Sub
- Defined in:
- lib/em/protocols/zmq2/pub_sub.rb
Overview
ZMQ socket which acts as SUB subscriptions are done by subscribe method
Defined Under Namespace
Classes: DefaultAction
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Sub
constructor
A new instance of Sub.
- #receive_message(message) ⇒ Object
- #receive_message_and_peer(message, peer) ⇒ Object
- #subscribe(s, cb = nil, &block) ⇒ Object
- #subscribe_many(subscriptions) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Sub
Returns a new instance of Sub.
19 20 21 22 23 24 |
# File 'lib/em/protocols/zmq2/pub_sub.rb', line 19 def initialize(opts = {}) super @subscriptions = {} @default_action = DefaultAction.new(self) subscribe_many [*opts[:subscribe]] end |
Instance Method Details
#receive_message(message) ⇒ Object
47 48 49 |
# File 'lib/em/protocols/zmq2/pub_sub.rb', line 47 def () raise NoMethodError end |
#receive_message_and_peer(message, peer) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/em/protocols/zmq2/pub_sub.rb', line 34 def (, peer) for sub, callback in @subscriptions matched = if String === sub .first.start_with?(sub) elsif sub.respond_to?(:call) sub.call(.first) else sub === .first # Regexp and anything you want end callback.call() if matched end end |
#subscribe(s, cb = nil, &block) ⇒ Object
30 31 32 |
# File 'lib/em/protocols/zmq2/pub_sub.rb', line 30 def subscribe(s, cb = nil, &block) @subscriptions[s] = cb || block || @default_action end |
#subscribe_many(subscriptions) ⇒ Object
26 27 28 |
# File 'lib/em/protocols/zmq2/pub_sub.rb', line 26 def subscribe_many(subscriptions) subscriptions.each{|sub| subscribe *sub} if subscriptions end |