Parent

Celluloid::IO::Reactor

React to external I/O events. This is kinda sorta supposed to resemble the Reactor design pattern.

Public Class Methods

new() click to toggle source
# File lib/celluloid/io/reactor.rb, line 15
def initialize
  @selector = NIO::Selector.new
  @monitors = {}
end

Public Instance Methods

run_once(timeout = nil) click to toggle source

Run the reactor, waiting for events or wakeup signal

# File lib/celluloid/io/reactor.rb, line 56
def run_once(timeout = nil)
  @selector.select(timeout) do |monitor|
    monitor.value.resume
  end
end
wait(io) click to toggle source

Wait for the given IO operation to complete

# File lib/celluloid/io/reactor.rb, line 35
def wait(io)
  # zomg ugly type conversion :(
  unless io.is_a?(::IO) or io.is_a?(OpenSSL::SSL::SSLSocket)
    if io.respond_to? :to_io
      io = io.to_io
    elsif ::IO.respond_to? :try_convert
      io = ::IO.try_convert(io)
    end

    raise TypeError, "can't convert #{io.class} into IO" unless io.is_a?(::IO)
  end

  unless monitor = @monitors[io]
    monitor = Monitor.new(@selector, io)
    @monitors[io] = monitor
  end

  yield monitor
end
wait_readable(io) click to toggle source

Wait for the given IO object to become readable

# File lib/celluloid/io/reactor.rb, line 21
def wait_readable(io)
  wait io do |monitor|
    monitor.wait_readable
  end
end
wait_writable(io) click to toggle source

Wait for the given IO object to become writable

# File lib/celluloid/io/reactor.rb, line 28
def wait_writable(io)
  wait io do |monitor|
    monitor.wait_writable
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.