Sha256: d180948b3b5c05fd0682814737229c380129d30dc9ed75673117176597d0bff2
Contents?: true
Size: 640 Bytes
Versions: 24
Compression:
Stored size: 640 Bytes
Contents
# -*- encoding: binary -*- # :enddoc: require 'thread' # Thread pool class based on pulling off a single Ruby Queue. # This is NOT used for the ThreadPool class, since that class does not # need a userspace Queue. class Rainbows::QueuePool attr_reader :queue def initialize(size = 20) q = Queue.new @threads = (1..size).map do Thread.new do while job = q.shift yield job end end end @queue = q end def quit! @threads.each { |_| @queue << nil } @threads.delete_if do |t| Rainbows.tick t.alive? ? t.join(0.01) : true end until @threads.empty? end end
Version data entries
24 entries across 24 versions & 1 rubygems