lib/performer/queue.rb in performer-1.0.0 vs lib/performer/queue.rb in performer-1.0.1

- old
+ new

@@ -1,12 +1,14 @@ +require "monitor" + class Performer # Similar to the stdlib Queue, but with a thread-safe way of closing it down. class Queue def initialize @queue = [] - @queue_mutex = Mutex.new - @queue_cond = Performer::ConditionVariable.new + @queue_mutex = Monitor.new + @queue_cond = @queue_mutex.new_cond @undefined = {} @open = true end # Push an object into the queue, or yield if not possible. @@ -55,12 +57,10 @@ unless block_given? raise ArgumentError, "no block given" end obj, was_open = @queue_mutex.synchronize do - while empty? and open? - @queue_cond.wait(@queue_mutex) - end + @queue_cond.wait_while { empty? and open? } obj = if empty? undefined else queue.shift