Class: Green::ZMQ::Waiter
- Inherits:
-
Object
- Object
- Green::ZMQ::Waiter
- Defined in:
- lib/green/zmq.rb
Instance Attribute Summary collapse
-
#socket_waiter ⇒ Object
readonly
Returns the value of attribute socket_waiter.
-
#waiters ⇒ Object
readonly
Returns the value of attribute waiters.
Instance Method Summary collapse
- #cancel ⇒ Object
-
#initialize(fd) ⇒ Waiter
constructor
A new instance of Waiter.
- #lock ⇒ Object
- #wake ⇒ Object
Constructor Details
#initialize(fd) ⇒ Waiter
Returns a new instance of Waiter.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/green/zmq.rb', line 8 def initialize(fd) @socket_waiter = Green.hub.socket_waiter(Socket.for_fd(fd)) @waiters = [] @notifier = Green.spawn do while true @socket_waiter.wait_read wake end end end |
Instance Attribute Details
#socket_waiter ⇒ Object (readonly)
Returns the value of attribute socket_waiter.
7 8 9 |
# File 'lib/green/zmq.rb', line 7 def socket_waiter @socket_waiter end |
#waiters ⇒ Object (readonly)
Returns the value of attribute waiters.
7 8 9 |
# File 'lib/green/zmq.rb', line 7 def waiters @waiters end |
Instance Method Details
#cancel ⇒ Object
30 31 32 |
# File 'lib/green/zmq.rb', line 30 def cancel @notifier.kill end |
#lock ⇒ Object
19 20 21 22 23 |
# File 'lib/green/zmq.rb', line 19 def lock g = Green.current @waiters << g Green.hub.wait { @waiters.delete g } end |
#wake ⇒ Object
25 26 27 28 |
# File 'lib/green/zmq.rb', line 25 def wake w = @waiters.shift Green.hub.callback { w.switch } if w end |