Class: ParticlePool::Pool

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

Instance Method Summary collapse

Constructor Details

#initializePool

Returns a new instance of Pool.



2
3
4
# File 'lib/particle_pool/pool.rb', line 2

def initialize
  @threads = []
end

Instance Method Details

#<<(t, *args, **kwargs) ⇒ Object



6
7
8
# File 'lib/particle_pool/pool.rb', line 6

def <<(t, *args, **kwargs)
  push(t, *args, **kwargs)
end

#push(t, *args, **kwargs) ⇒ Object



10
11
12
13
14
# File 'lib/particle_pool/pool.rb', line 10

def push(t, *args, **kwargs)
  thr = @threads.min
  raise 'no threads available' unless t
  thr.push(t, *args, **kwargs)
end

#start(size = Etc.nprocessors) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/particle_pool/pool.rb', line 16

def start(size = Etc.nprocessors)
  size.times do
    @threads << ParticlePool::PoolThread.new
  end
  @threads.each do |t|
    Thread.new do
      t.start
    end
  end
end