@note Only two threads can be used with this Turnstile
because of the current implementation.
Attributes
queue[RW]
Public Class Methods
new()click to toggle source
Initialize the turnstile.
# File lib/listen/turnstile.rb, line 12definitialize# Until Ruby offers semahpores, only queues can be used# to implement a turnstile.@queue = Queue.newend
Public Instance Methods
signal()click to toggle source
Unblocks the waiting thread if any.
# File lib/listen/turnstile.rb, line 26defsignalqueue.push(:dummy) ifqueue.num_waiting==1end
wait()click to toggle source
Blocks the current thread until a signal is received.
# File lib/listen/turnstile.rb, line 20defwaitqueue.popifqueue.num_waiting==0end