class Async::Variable

A synchronization primitive that allows one task to wait for another task to resolve a value.

def initialize(condition = Condition.new)

@parameter condition [Condition] The condition to use for synchronization.

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

def resolve(value = true)

@parameter value [Object] The value to resolve.

Signals all waiting tasks.

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

def resolved?

@returns [Boolean] Whether the value has been resolved.

Whether the value has been resolved.
def resolved?
	@condition.nil?
end

def value

@returns [Object] The resolved value.

Wait for the value to be resolved.
def value
	@condition&.wait
	return @value
end

def wait

Alias for {#value}.
def wait
	self.value
end