Sha256: 5cadb4e67e135472a90d645d74b29e5023a2ec0fbcb724da2905cfd5b6be2140

Contents?: true

Size: 557 Bytes

Versions: 27

Compression:

Stored size: 557 Bytes

Contents

# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2021-2022, by Samuel Williams.

require_relative 'condition'

module Async
	class Variable
		def initialize(condition = Condition.new)
			@condition = condition
			@value = nil
		end
		
		def resolve(value = true)
			@value = value
			condition = @condition
			@condition = nil
			
			self.freeze
			
			condition.signal(value)
		end
		
		def resolved?
			@condition.nil?
		end
		
		def value
			@condition&.wait
			return @value
		end
		
		def wait
			self.value
		end
	end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
async-2.4.1 lib/async/variable.rb
async-2.4.0 lib/async/variable.rb
async-2.3.1 lib/async/variable.rb
async-2.3.0 lib/async/variable.rb
async-2.2.1 lib/async/variable.rb
async-2.2.0 lib/async/variable.rb
async-2.1.0 lib/async/variable.rb