Class: Fairy::Reference
- Inherits:
-
Object
- Object
- Fairy::Reference
- Defined in:
- lib/fairy/share/reference.rb
Defined Under Namespace
Classes: NullValue
Constant Summary collapse
Instance Method Summary collapse
- #arrived? ⇒ Boolean
-
#initialize ⇒ Reference
constructor
A new instance of Reference.
- #value ⇒ Object
- #value=(v) ⇒ Object
- #wait_arrived ⇒ Object
Constructor Details
#initialize ⇒ Reference
Returns a new instance of Reference.
13 14 15 16 17 |
# File 'lib/fairy/share/reference.rb', line 13 def initialize @value = NULL_VALUE @value_mutex = Mutex.new @value_cv = ConditionVariable.new end |
Instance Method Details
#arrived? ⇒ Boolean
35 36 37 38 39 |
# File 'lib/fairy/share/reference.rb', line 35 def arrived? @value_mutex.synchronize do @value != NULL_VALUE end end |
#value ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/fairy/share/reference.rb', line 19 def value @value_mutex.synchronize do while @value == NULL_VALUE @value_cv.wait(@value_mutex) end end @value end |
#value=(v) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/fairy/share/reference.rb', line 28 def value=(v) @value_mutex.synchronize do @value = v @value_cv.broadcast end end |
#wait_arrived ⇒ Object
41 42 43 |
# File 'lib/fairy/share/reference.rb', line 41 def wait_arrived value end |