Class: Async::IO

Inherits:
Wrapper show all
Extended by:
Forwardable
Defined in:
lib/async/io.rb

Overview

Represents an asynchronous IO within a reactor.

Direct Known Subclasses

BasicSocket, SSLSocket

Constant Summary collapse

WRAPPERS =
{}

Instance Attribute Summary

Attributes inherited from Wrapper

#io, #task

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Wrapper

#close, #initialize, #monitor, #wait_any, #wait_readable, #wait_writable

Constructor Details

This class inherits a constructor from Async::Wrapper

Class Method Details

.[](instance) ⇒ Object



32
33
34
# File 'lib/async/io.rb', line 32

def self.[] instance
	WRAPPERS[instance.class]
end

.wraps(klass, *additional_methods) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'lib/async/io.rb', line 57

def wraps(klass, *additional_methods)
	WRAPPERS[klass] = self
	
	klass.instance_methods(false).grep(/(.*)_nonblock/) do |method_name|
		wrap_blocking_method($1, method_name)
	end
	
	def_delegators :@io, *(additional_methods - instance_methods(false))
end

Instance Method Details

#wrap_blocking_method(new_name, method_name) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/async/io.rb', line 38

def wrap_blocking_method(new_name, method_name)
	# puts "#{self}\##{$1} -> #{method_name}"
	define_method(new_name) do |*args|
		async do
			@io.__send__(method_name, *args, exception: false)
		end
	end
end