Class: Buster::Poller

Inherits:
Object
  • Object
show all
Defined in:
lib/buster/poller.rb

Instance Method Summary collapse

Constructor Details

#initializePoller

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

#startObject



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

#stopObject



18
19
20
# File 'lib/buster/poller.rb', line 18

def stop
  @run = false
end