Class: Concurrent::Selectable::Base
- Inherits:
-
Object
- Object
- Concurrent::Selectable::Base
- Defined in:
- lib/concurrent/selectable/common.rb
Overview
Base class for selectable primitives
Instance Method Summary collapse
-
#close ⇒ Object
Manually releases the IO resources associated with the primitive.
-
#initialize ⇒ Base
constructor
:nodoc:.
-
#to_io ⇒ Object
Converts the primitive to an IO object; the object is only safe to test whether it is ready for reading; DO NOT read from the returned IO object yourself.
-
#wait(timeout = nil) ⇒ Object
Waits for the primitive to become available/signaled, with the given
timeout(see IO.select).
Constructor Details
#initialize ⇒ Base
:nodoc:
45 46 47 |
# File 'lib/concurrent/selectable/common.rb', line 45 def initialize #:nodoc: @read, @write = IO.pipe end |
Instance Method Details
#close ⇒ Object
Manually releases the IO resources associated with the primitive
66 67 68 69 70 71 72 73 |
# File 'lib/concurrent/selectable/common.rb', line 66 def close [ @read, @write ].each do |port| begin port.close rescue Exception end end end |
#to_io ⇒ Object
Converts the primitive to an IO object; the object is only safe to test whether it is ready for reading; DO NOT read from the returned IO object yourself.
61 62 63 |
# File 'lib/concurrent/selectable/common.rb', line 61 def to_io @read end |
#wait(timeout = nil) ⇒ Object
Waits for the primitive to become available/signaled, with the given timeout (see IO.select). If timeout is given and is not nil, then TimeoutError will be raised if the timeout is exceeded.
52 53 54 55 56 |
# File 'lib/concurrent/selectable/common.rb', line 52 def wait(timeout=nil) ready = IO.select([@read], nil, nil, timeout) raise TimeoutError, "wait timed out" unless ready self end |