Sha256: 672b521ae47cad53467cbc5f9adae82e28d16d48e27cec2d3a5aee1d71c545c5

Contents?: true

Size: 527 Bytes

Versions: 51

Compression:

Stored size: 527 Bytes

Contents

module Flydata

class QueueableThread
  MAX_JOBS = 60
  def initialize(max_jobs = MAX_JOBS)
    @queue = SizedQueue.new(max_jobs)
    @stop = false
    @thread = Thread.new(&method(:run_loop))
    @thread.abort_on_exception = true
  end

  def run(&block)
    @queue << block
  end

  def join
    @stop = true
    @queue << nil if @queue.empty?  # wake up the thread
    @thread.join
  end

  private

  def run_loop
    until @stop && @queue.empty?
      block = @queue.shift
      block.call if block
    end
  end
end

end

Version data entries

51 entries across 51 versions & 1 rubygems

Version Path
flydata-0.7.13 lib/flydata/queueable_thread.rb
flydata-0.7.12 lib/flydata/queueable_thread.rb
flydata-0.7.11 lib/flydata/queueable_thread.rb
flydata-0.7.10 lib/flydata/queueable_thread.rb
flydata-0.7.9 lib/flydata/queueable_thread.rb
flydata-0.7.8 lib/flydata/queueable_thread.rb
flydata-0.7.7 lib/flydata/queueable_thread.rb
flydata-0.7.6 lib/flydata/queueable_thread.rb
flydata-0.7.5 lib/flydata/queueable_thread.rb
flydata-0.7.4 lib/flydata/queueable_thread.rb
flydata-0.7.2.1 lib/flydata/queueable_thread.rb
flydata-0.7.2 lib/flydata/queueable_thread.rb
flydata-0.7.1 lib/flydata/queueable_thread.rb
flydata-0.7.0 lib/flydata/queueable_thread.rb
flydata-0.6.14 lib/flydata/queueable_thread.rb
flydata-0.6.13 lib/flydata/queueable_thread.rb
flydata-0.6.12 lib/flydata/queueable_thread.rb
flydata-0.6.11 lib/flydata/queueable_thread.rb
flydata-0.6.10 lib/flydata/queueable_thread.rb
flydata-0.6.9 lib/flydata/queueable_thread.rb