Class: Async::Queue

Inherits:
Notification show all
Defined in:
lib/async/queue.rb

Overview

A queue which allows items to be processed in order.

Direct Known Subclasses

LimitedQueue

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Notification

#signal

Methods inherited from Condition

#empty?, #signal, #wait

Constructor Details

#initializeQueue

Returns a new instance of Queue.



26
27
28
29
30
# File 'lib/async/queue.rb', line 26

def initialize
	super
	
	@items = []
end

Instance Attribute Details

#itemsObject (readonly)

Returns the value of attribute items.



32
33
34
# File 'lib/async/queue.rb', line 32

def items
  @items
end

Instance Method Details

#async(&block) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/async/queue.rb', line 50

def async(&block)
	parent = Task.current
	
	while item = self.dequeue
		parent.async(item, &block)
	end
end

#dequeueObject



42
43
44
45
46
47
48
# File 'lib/async/queue.rb', line 42

def dequeue
	while @items.empty?
		self.wait
	end
	
	@items.shift
end

#enqueue(item) ⇒ Object Also known as: <<



34
35
36
37
38
# File 'lib/async/queue.rb', line 34

def enqueue item
	@items.push(item)
	
	self.signal unless self.empty?
end