Class: Bran::FiberManager
- Inherits:
-
Object
- Object
- Bran::FiberManager
- Defined in:
- lib/bran/fiber_manager.rb
Instance Attribute Summary collapse
-
#loop ⇒ Object
readonly
TODO: hide loop when rest of interface is stable.
Instance Method Summary collapse
-
#initialize ⇒ FiberManager
constructor
A new instance of FiberManager.
- #resume_soon(fiber) ⇒ Object
- #run! ⇒ Object
- #stop! ⇒ Object
- #wait_for_readable!(fd) ⇒ Object
- #wait_for_seconds!(seconds) ⇒ Object
- #wait_for_writable!(fd) ⇒ Object
Constructor Details
#initialize ⇒ FiberManager
Returns a new instance of FiberManager.
8 9 10 |
# File 'lib/bran/fiber_manager.rb', line 8 def initialize @loop = LibUV::Reactor.new end |
Instance Attribute Details
#loop ⇒ Object (readonly)
TODO: hide loop when rest of interface is stable
6 7 8 |
# File 'lib/bran/fiber_manager.rb', line 6 def loop @loop end |
Instance Method Details
#resume_soon(fiber) ⇒ Object
42 43 44 |
# File 'lib/bran/fiber_manager.rb', line 42 def resume_soon(fiber) @loop.timer_oneshot_wake(0, fiber) end |
#run! ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/bran/fiber_manager.rb', line 12 def run! Thread.current.thread_variable_set(:fiber_manager, self) yield if block_given? @loop.run! ensure Thread.current.thread_variable_set(:fiber_manager, nil) end |
#stop! ⇒ Object
22 23 24 25 |
# File 'lib/bran/fiber_manager.rb', line 22 def stop! Thread.current.thread_variable_set(:fiber_manager, nil) @loop.stop! end |
#wait_for_readable!(fd) ⇒ Object
27 28 29 30 |
# File 'lib/bran/fiber_manager.rb', line 27 def wait_for_readable!(fd) @loop.push_readable(Integer(fd), ::Fiber.current, false) ::Fiber.yield end |
#wait_for_seconds!(seconds) ⇒ Object
37 38 39 40 |
# File 'lib/bran/fiber_manager.rb', line 37 def wait_for_seconds!(seconds) @loop.timer_oneshot_wake(seconds, ::Fiber.current) ::Fiber.yield end |
#wait_for_writable!(fd) ⇒ Object
32 33 34 35 |
# File 'lib/bran/fiber_manager.rb', line 32 def wait_for_writable!(fd) @loop.push_writable(Integer(fd), ::Fiber.current, true) ::Fiber.yield end |