Class: Fairy::Reference

Inherits:
Object
  • Object
show all
Defined in:
lib/fairy/share/reference.rb

Defined Under Namespace

Classes: NullValue

Constant Summary collapse

NULL_VALUE =
NullValue.new

Instance Method Summary collapse

Constructor Details

#initializeReference

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

Returns:

  • (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

#valueObject



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_arrivedObject



41
42
43
# File 'lib/fairy/share/reference.rb', line 41

def wait_arrived
  value
end