Class: Nuggets::IO::InteractMixin::Interaction
- Defined in:
- lib/nuggets/io/interact_mixin.rb
Constant Summary collapse
- DEFAULT_MAXLEN =
2 ** 16
Instance Attribute Summary collapse
-
#maxlen ⇒ Object
Returns the value of attribute maxlen.
-
#readers ⇒ Object
readonly
Returns the value of attribute readers.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#writers ⇒ Object
readonly
Returns the value of attribute writers.
Instance Method Summary collapse
-
#initialize(input, output, timeout = nil, maxlen = nil) ⇒ Interaction
constructor
A new instance of Interaction.
- #interact ⇒ Object
Constructor Details
#initialize(input, output, timeout = nil, maxlen = nil) ⇒ Interaction
Returns a new instance of Interaction.
86 87 88 89 90 91 92 93 |
# File 'lib/nuggets/io/interact_mixin.rb', line 86 def initialize(input, output, timeout = nil, maxlen = nil) @readers, @writers = {}, {} output.each { |key, val| @readers[key] = initialize_reader(val) } input.each { |key, val| @writers[val] = [initialize_writer(key), ''] } @timeout, @maxlen = timeout, maxlen || DEFAULT_MAXLEN end |
Instance Attribute Details
#maxlen ⇒ Object
Returns the value of attribute maxlen.
97 98 99 |
# File 'lib/nuggets/io/interact_mixin.rb', line 97 def maxlen @maxlen end |
#readers ⇒ Object (readonly)
Returns the value of attribute readers.
95 96 97 |
# File 'lib/nuggets/io/interact_mixin.rb', line 95 def readers @readers end |
#timeout ⇒ Object
Returns the value of attribute timeout.
97 98 99 |
# File 'lib/nuggets/io/interact_mixin.rb', line 97 def timeout @timeout end |
#writers ⇒ Object (readonly)
Returns the value of attribute writers.
95 96 97 |
# File 'lib/nuggets/io/interact_mixin.rb', line 95 def writers @writers end |
Instance Method Details
#interact ⇒ Object
99 100 101 102 103 104 105 106 107 108 |
# File 'lib/nuggets/io/interact_mixin.rb', line 99 def interact until readers.empty? && writers.empty? handles = select(readers.keys, writers.keys, nil, timeout) or return handle_readers(handles[0]) handle_writers(handles[1]) end [] end |