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.12.1 lib/async/variable.rb
async-2.12.0 lib/async/variable.rb
async-2.11.0 lib/async/variable.rb
async-2.10.2 lib/async/variable.rb
async-2.10.1 lib/async/variable.rb
async-2.10.0 lib/async/variable.rb
async-2.9.0 lib/async/variable.rb
async-2.8.2 lib/async/variable.rb
async-2.8.1 lib/async/variable.rb
async-2.8.0 lib/async/variable.rb
async-2.7.0 lib/async/variable.rb
async-2.6.5 lib/async/variable.rb
async-2.6.4 lib/async/variable.rb
async-2.6.3 lib/async/variable.rb
async-2.6.2 lib/async/variable.rb
async-2.6.1 lib/async/variable.rb
async-2.6.0 lib/async/variable.rb
async-2.5.1 lib/async/variable.rb
async-2.5.0 lib/async/variable.rb
async-2.4.2 lib/async/variable.rb