Sha256: 65ee24580184d6cadc6bc4a1255829f56acebdd1f568b0fb56b03cc56fb281a6
Contents?: true
Size: 812 Bytes
Versions: 17
Compression:
Stored size: 812 Bytes
Contents
module Steep class ThreadWaiter attr_reader :queue, :waiter_threads def initialize(objects = nil) @queue = Thread::Queue.new() @waiter_threads = Set[].compare_by_identity if objects objects.each do |object| thread = yield(object) self << thread end end end def <<(thread) waiter_thread = Thread.new(thread) do |thread| # @type var thread: Thread Thread.current.report_on_exception = false begin thread.join ensure queue << thread end end waiter_threads << waiter_thread self end def wait_one unless waiter_threads.empty? th = queue.pop() or raise waiter_threads.delete(th) th end end end end
Version data entries
17 entries across 17 versions & 3 rubygems