Allows two threads to wait on eachother.
@note Only two threads can be used with this Turnstile
because of the current implementation.
Initialize the turnstile.
# File lib/listen/turnstile.rb, line 10 def initialize # Until ruby offers semahpores, only queues can be used # to implement a turnstile. @q = Queue.new end
Unblocks the waiting thread if there is one.
# File lib/listen/turnstile.rb, line 24 def signal @q.push :dummy if @q.num_waiting == 1 end
Blocks the current thread until a signal is received.
# File lib/listen/turnstile.rb, line 18 def wait @q.pop if @q.num_waiting == 0 end