Class: Celluloid::Util::FiberPool
- Inherits:
-
Object
- Object
- Celluloid::Util::FiberPool
- Defined in:
- lib/celluloid/util/fiber_pool.rb
Instance Attribute Summary collapse
-
#stats ⇒ Object
Returns the value of attribute stats.
Instance Method Summary collapse
- #acquire(&block) ⇒ Object
-
#initialize(trim_size = 64) ⇒ FiberPool
constructor
A new instance of FiberPool.
Constructor Details
#initialize(trim_size = 64) ⇒ FiberPool
6 7 8 9 10 11 |
# File 'lib/celluloid/util/fiber_pool.rb', line 6 def initialize(trim_size = 64) @trim_size = trim_size @pool = {} @stats = { created: 0, acquired: 0, trimmed: 0, sweep_counter: 0, terminated: 0, terminated_threads: 0, sweeps: 0 } @mutex = Mutex.new end |
Instance Attribute Details
#stats ⇒ Object
Returns the value of attribute stats.
4 5 6 |
# File 'lib/celluloid/util/fiber_pool.rb', line 4 def stats @stats end |
Instance Method Details
#acquire(&block) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/celluloid/util/fiber_pool.rb', line 13 def acquire(&block) trim sweep @stats[:acquired] += 1 fiber = fiber_pool.shift || create_fiber fiber.resume(block) fiber end |