Class: Sumac::RemoteEntry
Instance Method Summary collapse
- #cancel ⇒ Object
- #complete? ⇒ Boolean
- #get ⇒ Object
-
#initialize ⇒ RemoteEntry
constructor
A new instance of RemoteEntry.
- #set(new_value = nil) ⇒ Object
Constructor Details
#initialize ⇒ RemoteEntry
Returns a new instance of RemoteEntry.
4 5 6 7 8 9 10 |
# File 'lib/sumac/remote_entry.rb', line 4 def initialize @mutex = Mutex.new @condition_variable = ConditionVariable.new @value = nil @value_set = false @complete = false end |
Instance Method Details
#cancel ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/sumac/remote_entry.rb', line 12 def cancel @mutex.synchronize do @complete = true @value_set = false @value = false end end |
#complete? ⇒ Boolean
37 38 39 |
# File 'lib/sumac/remote_entry.rb', line 37 def complete? @complete end |
#get ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/sumac/remote_entry.rb', line 20 def get @mutex.synchronize do @condition_variable.wait(@mutex) unless complete? raise ClosedError unless @value_set @value end end |
#set(new_value = nil) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/sumac/remote_entry.rb', line 28 def set(new_value = nil) @mutex.synchronize do @value_set = true @complete = true @value = new_value @condition_variable.broadcast end end |