Sha256: 2c313105e4ddad2212432a819089452410502cf9a757df603471122e8424ccff

Contents?: true

Size: 719 Bytes

Versions: 6

Compression:

Stored size: 719 Bytes

Contents

#!/usr/bin/env ruby
# frozen_string_literal: true

# require 'async'; require 'async/queue'

require_relative '../../lib/async'; require_relative '../../lib/async/queue'

Async do |consumer|
	consumer.annotate "consumer"
	condition = Async::Condition.new
	
	producer = Async do |subtask|
		subtask.annotate "subtask"
		
		(1..).each do |value|
			puts "producer yielding"
			subtask.yield # (1) Fiber.yield, (3) Reactor -> producer.resume
			condition.signal(value) # (4) consumer.resume(value)
		end
		
		puts "producer exiting"
	end
	
	value = condition.wait # (2) value = Fiber.yield
	puts "producer.stop"
	producer.stop # (5) [producer is resumed already] producer.stop
	
	puts "consumer exiting"
end

puts "Done."

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
async-1.26.1 examples/stop/condition.rb
async-1.26.0 examples/stop/condition.rb
async-1.25.2 examples/stop/condition.rb
async-1.25.1 examples/stop/condition.rb
async-1.25.0 examples/stop/condition.rb
async-1.24.2 examples/stop/condition.rb