Class: Libuv::FiberPool
Overview
Use of a Fiber Pool increases performance as stack allocations don’t need to continually occur. Especially useful on JRuby and Rubinius where multiple kernel threads and locks emulate Fibers.
Instance Method Summary collapse
- #available ⇒ Object
- #exec ⇒ Object
-
#initialize(thread) ⇒ FiberPool
constructor
A new instance of FiberPool.
- #on_error(&block) ⇒ Object
- #reset ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(thread) ⇒ FiberPool
Returns a new instance of FiberPool.
9 10 11 12 |
# File 'lib/libuv/fiber_pool.rb', line 9 def initialize(thread) @reactor = thread reset end |
Instance Method Details
#available ⇒ Object
38 39 40 |
# File 'lib/libuv/fiber_pool.rb', line 38 def available @pool.size end |
#exec ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/libuv/fiber_pool.rb', line 14 def exec if @reactor.reactor_thread? # Execute the block in a Fiber next_fiber do begin yield rescue Exception => e @on_error.call(e) if @on_error end end else # move the block onto the reactor thread @reactor.schedule do exec do yield end end end end |
#on_error(&block) ⇒ Object
34 35 36 |
# File 'lib/libuv/fiber_pool.rb', line 34 def on_error(&block) @on_error = block end |
#reset ⇒ Object
46 47 48 49 |
# File 'lib/libuv/fiber_pool.rb', line 46 def reset @pool = [] @count = 0 end |
#size ⇒ Object
42 43 44 |
# File 'lib/libuv/fiber_pool.rb', line 42 def size @count end |