Class: Pool

Inherits:
Object
  • Object
show all
Defined in:
lib/pool.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Pool

Returns a new instance of Pool.



2
3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/pool.rb', line 2

def initialize(options)
  @min_threads = options[:threads]
  @queue = Queue.new
  @threads = []
  @min_threads.times do |i|
    @threads << Thread.new {
      while true
        block = @queue.pop
        block.call
      end
    }
  end
end

Instance Method Details

#<<(block) ⇒ Object



16
17
18
# File 'lib/pool.rb', line 16

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