Class: Async::Variable

Inherits:
Object
  • Object
show all
Defined in:
lib/async/variable.rb

Instance Method Summary collapse

Constructor Details

#initialize(condition = Condition.new) ⇒ Variable

Returns a new instance of Variable.



27
28
29
30
# File 'lib/async/variable.rb', line 27

def initialize(condition = Condition.new)
  @condition = condition
  @value = nil
end

Instance Method Details

#resolve(value = true) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/async/variable.rb', line 32

def resolve(value = true)
  @value = value
  condition = @condition
  @condition = nil
  
  self.freeze
  
  condition.signal(value)
end

#resolved?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/async/variable.rb', line 42

def resolved?
  @condition.nil?
end

#valueObject



46
47
48
49
# File 'lib/async/variable.rb', line 46

def value
  @condition&.wait
  return @value
end

#waitObject



51
52
53
# File 'lib/async/variable.rb', line 51

def wait
  self.value
end