Class: Green::ZMQ::Waiter

Inherits:
Object
  • Object
show all
Defined in:
lib/green/zmq.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_waiterObject (readonly)

Returns the value of attribute socket_waiter.



7
8
9
# File 'lib/green/zmq.rb', line 7

def socket_waiter
  @socket_waiter
end

#waitersObject (readonly)

Returns the value of attribute waiters.



7
8
9
# File 'lib/green/zmq.rb', line 7

def waiters
  @waiters
end

Instance Method Details

#cancelObject



30
31
32
# File 'lib/green/zmq.rb', line 30

def cancel
  @notifier.kill
end

#lockObject



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

#wakeObject



25
26
27
28
# File 'lib/green/zmq.rb', line 25

def wake
  w = @waiters.shift
  Green.hub.callback { w.switch } if w
end