Class: LightIO::Core::Backend::NIO
- Inherits:
-
Object
- Object
- LightIO::Core::Backend::NIO
- Defined in:
- lib/lightio/core/backend/nio.rb
Overview
LightIO use NIO as default event-driving backend
Instance Method Summary collapse
- #add_callback(&blk) ⇒ Object
- #add_io_wait(io, interests, &blk) ⇒ Object
- #add_timer(timer) ⇒ Object
- #cancel_io_wait(io) ⇒ Object
- #cancel_timer(timer) ⇒ Object
-
#initialize ⇒ NIO
constructor
A new instance of NIO.
- #run ⇒ Object
- #stop ⇒ Object
Constructor Details
Instance Method Details
#add_callback(&blk) ⇒ Object
73 74 75 |
# File 'lib/lightio/core/backend/nio.rb', line 73 def add_callback(&blk) @callbacks << blk end |
#add_io_wait(io, interests, &blk) ⇒ Object
85 86 87 88 89 |
# File 'lib/lightio/core/backend/nio.rb', line 85 def add_io_wait(io, interests, &blk) monitor = @selector.register(io, interests) monitor.value = blk monitor end |
#add_timer(timer) ⇒ Object
77 78 79 |
# File 'lib/lightio/core/backend/nio.rb', line 77 def add_timer(timer) timer.uuid = @timers.add_timer(timer) end |
#cancel_io_wait(io) ⇒ Object
91 92 93 |
# File 'lib/lightio/core/backend/nio.rb', line 91 def cancel_io_wait(io) @selector.deregister(io) end |
#cancel_timer(timer) ⇒ Object
81 82 83 |
# File 'lib/lightio/core/backend/nio.rb', line 81 def cancel_timer(timer) @timers.cancel_timer(timer) end |
#run ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/lightio/core/backend/nio.rb', line 61 def run raise Error, "already running" if @running @running = true loop do @current_loop_time = Time.now run_timers run_callbacks handle_selectables end end |
#stop ⇒ Object
95 96 97 98 99 |
# File 'lib/lightio/core/backend/nio.rb', line 95 def stop return unless @running @running = false raise end |