Class: MaZMQ::Pull
- Inherits:
-
SocketHandler
- Object
- SocketHandler
- MaZMQ::Pull
- Defined in:
- lib/ma-zmq/pull.rb
Instance Attribute Summary collapse
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Instance Method Summary collapse
-
#initialize ⇒ Pull
constructor
A new instance of Pull.
- #on_timeout(&block) ⇒ Object
- #recv_string ⇒ Object
- #timeout(secs) ⇒ Object
Methods inherited from SocketHandler
#addresses, #bind, #close, #connect, #identity, #identity=, #on_read, #on_write, #send_string, #socket_type
Constructor Details
#initialize ⇒ Pull
Returns a new instance of Pull.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/ma-zmq/pull.rb', line 5 def initialize @socket_type = ZMQ::PULL @last_try = nil @timeout = false # @cooldown super end |
Instance Attribute Details
#state ⇒ Object (readonly)
Returns the value of attribute state.
3 4 5 |
# File 'lib/ma-zmq/pull.rb', line 3 def state @state end |
Instance Method Details
#on_timeout(&block) ⇒ Object
44 45 46 47 |
# 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 ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# 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) ⇒ Object
40 41 42 |
# File 'lib/ma-zmq/pull.rb', line 40 def timeout(secs) @timeout = secs end |