Sha256: 6de41e7e01aee193589ad1d3647fa7363792294c9a540f7b6b0a444e1d26933b

Contents?: true

Size: 733 Bytes

Versions: 28

Compression:

Stored size: 733 Bytes

Contents

module Steep
  class ThreadWaiter
    attr_reader :objects, :queue, :waiter_threads

    def initialize(objects)
      @objects = objects
      @queue = Thread::Queue.new()
      @waiter_threads = Set[].compare_by_identity

      objects.each do |object|
        thread = yield(object)

        waiter_thread = Thread.new(thread) do |thread|
          Thread.current.report_on_exception = false

          begin
            thread.join
          ensure
            queue << [object, thread]
          end
        end

        waiter_threads << waiter_thread
      end
    end

    def wait_one
      unless waiter_threads.empty?
        obj, th = queue.pop()
        waiter_threads.delete(th)
        obj
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
steep-1.5.1 lib/steep/thread_waiter.rb
steep-1.5.0 lib/steep/thread_waiter.rb
steep-1.5.0.pre.6 lib/steep/thread_waiter.rb
steep-1.5.0.pre.5 lib/steep/thread_waiter.rb
steep-1.5.0.pre.4 lib/steep/thread_waiter.rb
steep-1.5.0.pre.3 lib/steep/thread_waiter.rb
steep-1.5.0.pre.2 lib/steep/thread_waiter.rb
steep-1.5.0.pre.1 lib/steep/thread_waiter.rb