Class: Mutant::Variable Private
- Inherits:
-
Object
- Object
- Mutant::Variable
- Defined in:
- lib/mutant/variable.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Lightweight shared variables
ignore :reek:TooManyMethods
Defined Under Namespace
Constant Summary collapse
- EMPTY =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Class.new do const_set(:INSPECT, 'Mutant::Variable::EMPTY') end.new.freeze
- TIMEOUT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Class.new do const_set(:INSPECT, 'Mutant::Variable::TIMEOUT') end.new.freeze
Instance Method Summary collapse
-
#initialize(condition_variable:, mutex:, value: EMPTY) ⇒ undefined
constructor
private
Initialize object.
-
#read ⇒ Object
private
Read value from variable.
-
#take ⇒ Object
private
Take value from mvar, block on empty.
-
#take_timeout(timeout) ⇒ Result::Timeout, Result::Value
private
Take value from mvar, with timeout.
-
#try_put(value) ⇒ self
private
Try put value into the variable, non blocking.
-
#with {|Object| ... } ⇒ Object
private
Execute block with value, blocking.
Constructor Details
#initialize(condition_variable:, mutex:, value: EMPTY) ⇒ undefined
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize object
59 60 61 62 63 |
# File 'lib/mutant/variable.rb', line 59 def initialize(condition_variable:, mutex:, value: EMPTY) @full = condition_variable.new @mutex = mutex.new @value = value end |
Instance Method Details
#read ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Read value from variable
98 99 100 101 102 103 |
# File 'lib/mutant/variable.rb', line 98 def read synchronize do wait_full @value end end |
#take ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Take value from mvar, block on empty
68 69 70 71 72 73 |
# File 'lib/mutant/variable.rb', line 68 def take synchronize do wait_full perform_take end end |
#take_timeout(timeout) ⇒ Result::Timeout, Result::Value
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Take value from mvar, with timeout
84 85 86 87 88 89 90 91 92 |
# File 'lib/mutant/variable.rb', line 84 def take_timeout(timeout) synchronize do if wait_timeout(@full, timeout, &method(:full?)) Result::Timeout.new else Result::Value.new(perform_take) end end end |
#try_put(value) ⇒ self
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Try put value into the variable, non blocking
110 111 112 113 114 115 116 |
# File 'lib/mutant/variable.rb', line 110 def try_put(value) synchronize do perform_put(value) if empty? end self end |
#with {|Object| ... } ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Execute block with value, blocking
124 125 126 127 128 129 |
# File 'lib/mutant/variable.rb', line 124 def with synchronize do wait_full yield @value end end |