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

Version Path
steep-1.10.0 lib/steep/thread_waiter.rb
steep-1.10.0.pre.3 lib/steep/thread_waiter.rb
steep-1.10.0.pre.2 lib/steep/thread_waiter.rb
steep-1.10.0.pre.1 lib/steep/thread_waiter.rb
steep-1.10.0.dev.1 lib/steep/thread_waiter.rb
steep-relaxed-1.9.4.3 lib/steep/thread_waiter.rb
steep-relaxed-1.9.3.3 lib/steep/thread_waiter.rb
steep-activesupport-4-1.9.4 lib/steep/thread_waiter.rb
steep-activesupport-4-1.9.3.1 lib/steep/thread_waiter.rb
steep-1.9.4 lib/steep/thread_waiter.rb
steep-activesupport-4-1.9.3 lib/steep/thread_waiter.rb
steep-1.9.3 lib/steep/thread_waiter.rb
steep-1.9.2 lib/steep/thread_waiter.rb
steep-1.9.1 lib/steep/thread_waiter.rb
steep-1.9.0 lib/steep/thread_waiter.rb
steep-1.9.0.dev.2 lib/steep/thread_waiter.rb
steep-1.9.0.dev.1 lib/steep/thread_waiter.rb