class MaZMQ::Pull

Attributes

state[R]

Public Class Methods

new() click to toggle source
Calls superclass method MaZMQ::SocketHandler::new
# File lib/ma-zmq/pull.rb, line 5
def initialize
  @socket_type = ZMQ::PULL

  @last_try = nil

  @timeout = false
  # @cooldown

  super
end

Public Instance Methods

on_timeout(&block) click to toggle source
# File lib/ma-zmq/pull.rb, line 44
def on_timeout(&block)
  return false if not @connection or block.arity != -1
  @connection.on_timeout(block)
end
recv_string() click to toggle source
Calls superclass method MaZMQ::SocketHandler#recv_string
# File lib/ma-zmq/pull.rb, line 16
def recv_string
  if @state == :idle
    @state = :pulling
  end
  case @state
    when :pulling
      @last_try ||= Time.now if @timeout

      msg = super

      if msg.empty?
        if @timeout and (Time.now - @last_try) > @timeout
          @state = :timeout
        end
      else
        @last_try = nil if @timeout
        @state = :idle
      end
      return msg
    when :timeout
      return false
  end
end
timeout(secs) click to toggle source
# File lib/ma-zmq/pull.rb, line 40
def timeout(secs)
  @timeout = secs
end