lib/circular_queue.rb in circular_queue-1.0.0 vs lib/circular_queue.rb in circular_queue-1.0.1
- old
+ new
@@ -41,28 +41,32 @@
clear
end
# Adds an item to the queue
# @param [Object] item item to add
+ # @return [CircularQueue] the queue itself
def enq(item)
@mutex.synchronize do
enq_item(item)
wakeup_next_waiter
+ self
end
end
alias << enq
alias push enq
# Adds an item to the queue, raising an error if the queue is full
# @param [Object] item item to add
# @raise [ThreadError] queue is full
+ # @return [CircularQueue] the queue itself
def enq!(item)
@mutex.synchronize do
raise ThreadError.new("Queue is full") if full?
enq_item(item)
wakeup_next_waiter
+ self
end
end
alias push! enq!
# Removes an item from the queue
@@ -85,14 +89,16 @@
end
alias shift deq
alias pop deq
# Removes all items from the queue
+ # @return [CircularQueue] the queue itself
def clear
@mutex.synchronize do
@size = 0
@front = 0
@back = 0
+ self
end
end
# Returns whether the queue is empty
# @return [Boolean] queue is empty