Class: Async::IO::Generic
- Inherits:
-
Wrapper
- Object
- Wrapper
- Async::IO::Generic
show all
- Extended by:
- Forwardable
- Defined in:
- lib/async/io/generic.rb
Overview
Represents an asynchronous IO within a reactor.
Constant Summary
collapse
- WRAPPERS =
{}
Class Attribute Summary collapse
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Class Attribute Details
.wrapped_klass ⇒ Object
Returns the value of attribute wrapped_klass.
59
60
61
|
# File 'lib/async/io/generic.rb', line 59
def wrapped_klass
@wrapped_klass
end
|
Instance Attribute Details
#timeout ⇒ Object
Returns the value of attribute timeout.
135
136
137
|
# File 'lib/async/io/generic.rb', line 135
def timeout
@timeout
end
|
Class Method Details
.wrap(*args) ⇒ Object
Instantiate a wrapped instance of the class, and optionally yield it to a given block, closing it afterwards.
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/async/io/generic.rb', line 73
def wrap(*args)
wrapper = self.new(@wrapped_klass.new(*args))
return wrapper unless block_given?
begin
yield wrapper
ensure
wrapper.close
end
end
|
.wrap_blocking_method(new_name, method_name, invert: true) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/async/io/generic.rb', line 45
def wrap_blocking_method(new_name, method_name, invert: true)
define_method(new_name) do |*args|
async_send(method_name, *args)
end
if invert
def_delegators :@io, method_name
end
end
|
.wraps(klass, *additional_methods) ⇒ Object
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/async/io/generic.rb', line 61
def wraps(klass, *additional_methods)
@wrapped_klass = klass
WRAPPERS[klass] = self
def_delegators :@io, *additional_methods
end
|
Instance Method Details
#connected? ⇒ Boolean
131
132
133
|
# File 'lib/async/io/generic.rb', line 131
def connected?
!@io.closed?
end
|
#dup ⇒ Object
100
101
102
103
104
|
# File 'lib/async/io/generic.rb', line 100
def dup
super.tap do |copy|
copy.timeout = self.timeout
end
end
|
#nonblock ⇒ Object
119
120
121
|
# File 'lib/async/io/generic.rb', line 119
def nonblock
true
end
|
#nonblock=(value) ⇒ Object
123
124
125
|
# File 'lib/async/io/generic.rb', line 123
def nonblock= value
true
end
|
#nonblock? ⇒ Boolean
127
128
129
|
# File 'lib/async/io/generic.rb', line 127
def nonblock?
true
end
|
#read ⇒ Object
Also known as:
sysread, readpartial
Invokes ‘read_nonblock` 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.
90
|
# File 'lib/async/io/generic.rb', line 90
wrap_blocking_method :read, :read_nonblock
|
#wait(timeout = self.timeout, mode = :read) ⇒ Object
106
107
108
109
110
111
112
113
114
115
116
117
|
# File 'lib/async/io/generic.rb', line 106
def wait(timeout = self.timeout, mode = :read)
case mode
when :read
wait_readable(timeout)
when :write
wait_writable(timeout)
else
wait_any(:rw, timeout)
end
rescue TimeoutError
return nil
end
|
#write ⇒ Object
Also known as:
syswrite, <<
Invokes ‘write_nonblock` 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.
96
|
# File 'lib/async/io/generic.rb', line 96
wrap_blocking_method :write, :write_nonblock
|