Class: ParticlePool::Pool
- Inherits:
-
Object
- Object
- ParticlePool::Pool
- Defined in:
- lib/particle_pool/pool.rb
Instance Method Summary collapse
- #<<(t, *args, **kwargs) ⇒ Object
-
#initialize ⇒ Pool
constructor
A new instance of Pool.
- #push(t, *args, **kwargs) ⇒ Object
- #start(size = Etc.nprocessors) ⇒ Object
Constructor Details
#initialize ⇒ Pool
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 |