class Async::IO::Generic
Represents an asynchronous IO within a reactor.
def async_send(*args)
def async_send(*args) while true result = @io.__send__(*args, exception: false) case result when :wait_readable wait_readable when :wait_writable wait_writable else return result end end end
def connected?
def connected? !@io.closed? end
def nonblock
def nonblock true end
def nonblock?
def nonblock? true end
def wait(timeout = nil, mode = :read)
def wait(timeout = nil, mode = :read) case mode when :read wait_readable(timeout) when :write wait_writable(timeout) else wait_any(:rw, timeout) end end
def wrap(*args)
def wrap(*args) wrapper = self.new(@wrapped_klass.new(*args)) return wrapper unless block_given? begin yield wrapper ensure wrapper.close end end
def wrap_blocking_method(new_name, method_name, invert: true)
@method $1
@!macro [attach] wrap_blocking_method
def wrap_blocking_method(new_name, method_name, invert: true) define_method(new_name) do |*args| async_send(method_name, *args) end if invert # We define the original _nonblock method to call the async variant. We ignore options. # define_method(method_name) do |*args, **options| # self.__send__(new_name, *args) # end def_delegators :@io, method_name end end
def wraps(klass, *additional_methods)
def wraps(klass, *additional_methods) @wrapped_klass = klass WRAPPERS[klass] = self # These are methods implemented by the wrapped class, that we aren't overriding, that may be of interest: # fallback_methods = klass.instance_methods(false) - instance_methods # puts "Forwarding #{klass} methods #{fallback_methods} to @io" def_delegators :@io, *additional_methods end