lib/steep/thread_waiter.rb in steep-1.8.3 vs lib/steep/thread_waiter.rb in steep-1.9.0.dev.1
- old
+ new
@@ -1,35 +1,43 @@
module Steep
class ThreadWaiter
- attr_reader :objects, :queue, :waiter_threads
+ attr_reader :queue, :waiter_threads
- def initialize(objects)
- @objects = objects
+ def initialize(objects = nil)
@queue = Thread::Queue.new()
@waiter_threads = Set[].compare_by_identity
- objects.each do |object|
- thread = yield(object)
+ if objects
+ objects.each do |object|
+ thread = yield(object)
+ self << thread
+ end
+ end
+ end
- waiter_thread = Thread.new(thread) do |thread|
- Thread.current.report_on_exception = false
+ def <<(thread)
+ waiter_thread = Thread.new(thread) do |thread|
+ # @type var thread: Thread
- begin
- thread.join
- ensure
- queue << [object, thread]
- end
- end
+ Thread.current.report_on_exception = false
- waiter_threads << waiter_thread
+ begin
+ thread.join
+ ensure
+ queue << thread
+ end
end
+
+ waiter_threads << waiter_thread
+
+ self
end
def wait_one
unless waiter_threads.empty?
- obj, th = queue.pop()
+ th = queue.pop() or raise
waiter_threads.delete(th)
- obj
+ th
end
end
end
end