class << self
Definitions
def wrap_blocking_method(new_name, method_name, invert: true, &block)
Invokes $2 on the underlying io. If the operation would block, the current task is paused until the operation can succeed, at which point it's resumed and the operation is completed.
Implementation
def wrap_blocking_method(new_name, method_name, invert: true, &block)
if block_given?
define_method(new_name, &block)
else
define_method(new_name) do |*args|
async_send(method_name, *args)
end
end
if invert
# We wrap the original _nonblock method, ignoring options.
define_method(method_name) do |*args, exception: false|
async_send(method_name, *args)
end
end
end
def wrap(*args)
Instantiate a wrapped instance of the class, and optionally yield it to a given block, closing it afterwards.
Implementation
def wrap(*args)
wrapper = self.new(@wrapped_klass.new(*args))
return wrapper unless block_given?
begin
yield wrapper
ensure
wrapper.close
end
end