class Variable
A synchronization primitive that allows one task to wait for another task to resolve a value.
Signature
- deprecated
Use
class Async::Promise
instead.
Definitions
def initialize(condition = Condition.new)
Create a new variable.
Signature
-
parameterã
condition
ãCondition
The condition to use for synchronization.
Implementation
def initialize(condition = Condition.new)
warn("`Async::Variable` is deprecated, use `Async::Promise` instead.", category: :deprecated, uplevel: 1) if $VERBOSE
@condition = condition
@value = nil
end
def resolve(value = true)
Resolve the value.
Signals all waiting tasks.
Signature
-
parameterã
value
ãObject
The value to resolve.
Implementation
def resolve(value = true)
@value = value
condition = @condition
@condition = nil
self.freeze
condition.signal(value)
end
def value=(value)
Alias for #resolve
.
Implementation
def value=(value)
self.resolve(value)
end
def resolved?
Whether the value has been resolved.
Signature
-
returnsã
Boolean
Whether the value has been resolved.
Implementation
def resolved?
@condition.nil?
end
def wait
Wait for the value to be resolved.
Signature
-
returnsã
Object
The resolved value.
Implementation
def wait
@condition&.wait
return @value
end
def value
Alias for #wait
.
Implementation
def value
self.wait
end