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.8.10.2 lib/flydata/queueable_thread.rb
flydata-0.8.10.1 lib/flydata/queueable_thread.rb
flydata-0.8.9.11 lib/flydata/queueable_thread.rb
flydata-0.8.10 lib/flydata/queueable_thread.rb
flydata-0.8.9 lib/flydata/queueable_thread.rb
flydata-0.8.8 lib/flydata/queueable_thread.rb
flydata-0.8.7 lib/flydata/queueable_thread.rb
flydata-0.8.6 lib/flydata/queueable_thread.rb
flydata-0.8.5 lib/flydata/queueable_thread.rb
flydata-0.8.4 lib/flydata/queueable_thread.rb
flydata-0.8.3 lib/flydata/queueable_thread.rb
flydata-0.8.2 lib/flydata/queueable_thread.rb
flydata-0.8.1 lib/flydata/queueable_thread.rb
flydata-0.8.0 lib/flydata/queueable_thread.rb
flydata-0.7.19 lib/flydata/queueable_thread.rb
flydata-0.7.18 lib/flydata/queueable_thread.rb
flydata-0.7.17 lib/flydata/queueable_thread.rb
flydata-0.7.16 lib/flydata/queueable_thread.rb
flydata-0.7.15 lib/flydata/queueable_thread.rb
flydata-0.7.14 lib/flydata/queueable_thread.rb