class Async::Wrapper

Represents an asynchronous IO within a reactor.

def close

Close the monitor.
def close
	close_monitor
	
	@io.close if @io
end

def close_monitor

def close_monitor
	if @monitor
		@monitor.close
		@monitor = nil
	end
end

def initialize(io, reactor = nil)

Parameters:
  • bound (Boolean) -- whether the underlying socket will be closed if the wrapper is closed.
  • reactor (Reactor) -- the reactor that is managing this wrapper, or not specified, it's looked up by way of {Task.current}.
  • io () -- the native object to wrap.
def initialize(io, reactor = nil)
	@io = io
	
	@reactor = reactor || Task.current.reactor
	@monitor = nil
end

def monitor(interests, duration = nil)

Monitor the io for the given events
def monitor(interests, duration = nil)
	unless @monitor
		@monitor = @reactor.register(@io, interests)
	else
		@monitor.interests = interests
	end
	
	@monitor.value = Fiber.current
	
	# If the user requested an explicit timeout for this operation:
	if duration
		@reactor.timeout(duration) do
			Task.yield
		end
	else
		Task.yield
	end
	
	return true
ensure
	@monitor.value = nil if @monitor
end

def wait_any(interests = :rw, duration = nil)

Parameters:
  • duration (Float) -- timeout after the given duration if not `nil`.
  • interests (:r | :w | :rw) -- what events to wait for.
def wait_any(interests = :rw, duration = nil)
	monitor(interests, duration)
end

def wait_readable(duration = nil)

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

def wait_writable(duration = nil)

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