Sha256: 56e13c0a4a717e8d8dc81b64f0149bbe84a473a0d6268be43f0edacd934a3a43

Contents?: true

Size: 383 Bytes

Versions: 7

Compression:

Stored size: 383 Bytes

Contents

#!/usr/bin/env ruby

require 'async'
require 'async/queue'

Async do
	# Queue of up to 10 items:
	items = Async::LimitedQueue.new(10)
	
	# Five producers:
	5.times do
		Async do |task|
			while true
				t = rand
				task.sleep(t)
				items.enqueue(t)
			end
		end
	end
	
	# A single consumer:
	Async do |task|
		while item = items.dequeue
			puts "dequeue -> #{item}"
		end
	end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
async-1.24.1 examples/queue/producer.rb
async-1.24.0 examples/queue/producer.rb
async-1.23.0 examples/queue/producer.rb
async-1.22.2 examples/queue/producer.rb
async-1.22.1 examples/queue/producer.rb
async-1.22.0 examples/queue/producer.rb
async-1.21.0 examples/queue/producer.rb