class Async::Wrapper

Represents an asynchronous IO within a reactor.

def close

Close the monitor.
def close
	@monitor.close if @monitor
	@monitor = nil
end

def initialize(io, task)

Parameters:
  • 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)

Parameters:
  • 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)

Parameters:
  • interests (:r | :w | :rw) -- what events to wait for.
def wait_any(interests = :rw)
	monitor(interests) do
		Task.yield
	end
end

def wait_readable

Wait for the io to become readable.
def wait_readable
	wait_any(:r)
end

def wait_writable

Wait for the io to become writable.
def wait_writable
	wait_any(:w)
end