Class: Buster::Poller
- Inherits:
-
Object
- Object
- Buster::Poller
- Defined in:
- lib/buster/poller.rb
Instance Method Summary collapse
-
#initialize ⇒ Poller
constructor
A new instance of Poller.
- #pipe(incoming, outgoing) ⇒ Object
- #register(socket, &block) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize ⇒ Poller
Returns a new instance of Poller.
3 4 5 |
# File 'lib/buster/poller.rb', line 3 def initialize @poller = ZMQ::Poller.new end |
Instance Method Details
#pipe(incoming, outgoing) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/buster/poller.rb', line 27 def pipe(incoming, outgoing) register(incoming) do |s| s.recv_strings(msgs = []) outgoing.send_strings(msgs, ZMQ::NOBLOCK) end end |
#register(socket, &block) ⇒ Object
22 23 24 25 |
# File 'lib/buster/poller.rb', line 22 def register(socket, &block) @poller.register(socket, ZMQ::POLLIN) readable_actions[socket] = block end |
#start ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/buster/poller.rb', line 7 def start @run = true while @run @poller.poll(500) @poller.readables.each do |socket| action = @readable_actions[socket] action.call(socket) if action end end end |
#stop ⇒ Object
18 19 20 |
# File 'lib/buster/poller.rb', line 18 def stop @run = false end |