Skip to content

Commit e9cc6f0

Browse files
authored
Redefine aliases for LimitedQueue (#367)
1 parent 367745d commit e9cc6f0

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

lib/async/queue.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,16 @@ def limited?
125125
# If the queue is full, this method will block until there is space available.
126126
#
127127
# @parameter item [Object] The item to add to the queue.
128-
def <<(item)
128+
def push(item)
129129
while limited?
130130
@full.wait
131131
end
132132

133133
super
134134
end
135+
136+
# Compatibility with {::Queue#push}.
137+
alias << push
135138

136139
# Add multiple items to the queue.
137140
#
@@ -163,5 +166,8 @@ def dequeue
163166

164167
return item
165168
end
169+
170+
# Compatibility with {::Queue#pop}.
171+
alias pop dequeue
166172
end
167173
end

test/async/queue.rb

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,13 +244,21 @@ def before
244244
queue << :item2
245245
end
246246

247-
reactor.async do |task|
248-
task.sleep 0.01
249-
expect(queue.items).to contain_exactly :item1
250-
queue.dequeue
251-
expect(queue.items).to contain_exactly :item2
247+
expect(queue.dequeue).to be == :item1
248+
expect(queue.dequeue).to be == :item2
249+
end
250+
251+
with "#pop" do
252+
it "waits until a queue is dequeued" do
253+
reactor.async do
254+
queue << :item2
255+
end
256+
257+
expect(queue.pop).to be == :item1
258+
expect(queue.pop).to be == :item2
252259
end
253260
end
254261
end
255262
end
256263
end
264+

0 commit comments

Comments
 (0)