Class: Fairy::Reference
- Inherits:
-
Object
- Object
- Fairy::Reference
- Defined in:
- lib/fairy/share/reference.rb
Defined Under Namespace
Classes: NullValue
Constant Summary collapse
- NULL_VALUE =
NullValue.new
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.
14 15 16 17 18 |
# File 'lib/fairy/share/reference.rb', line 14 def initialize @value = NULL_VALUE @value_mutex = Mutex.new @value_cv = XThread::ConditionVariable.new end |
Instance Method Details
#arrived? ⇒ Boolean
36 37 38 39 40 |
# File 'lib/fairy/share/reference.rb', line 36 def arrived? @value_mutex.synchronize do @value != NULL_VALUE end end |
#value ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/fairy/share/reference.rb', line 20 def value @value_mutex.synchronize do while @value == NULL_VALUE @value_cv.wait(@value_mutex) end end @value end |
#value=(v) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/fairy/share/reference.rb', line 29 def value=(v) @value_mutex.synchronize do @value = v @value_cv.broadcast end end |
#wait_arrived ⇒ Object
42 43 44 |
# File 'lib/fairy/share/reference.rb', line 42 def wait_arrived value end |