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