class Async::Wrapper
Represents an asynchronous IO within a reactor.
def close
def close @monitor.close if @monitor @monitor = nil end
def initialize(io, task)
-
task
(Task
) -- the task that is managing this wrapper. -
io
() -- the native object to wrap.
def initialize(io, task) @io = io @task = task @monitor = nil end
def monitor(interests)
-
interests
(:r | :w | :rw
) -- what events to wait for.
def monitor(interests) unless @monitor @monitor = @task.register(@io, interests) else @monitor.interests = interests end @monitor.value = Fiber.current yield ensure @monitor.value = nil if @monitor end
def wait_any(interests = :rw)
-
interests
(:r | :w | :rw
) -- what events to wait for.
def wait_any(interests = :rw) monitor(interests) do Task.yield end end
def wait_readable
def wait_readable wait_any(:r) end
def wait_writable
def wait_writable wait_any(:w) end