lib/tap/app/queue.rb in tap-0.19.0 vs lib/tap/app/queue.rb in tap-1.3.0

- old
+ new

@@ -1,20 +1,20 @@ require 'monitor' module Tap class App - # Queue allows thread-safe enqueing and dequeing of nodes and inputs for + # Queue allows thread-safe enqueing and dequeing of tasks and inputs for # execution. # # === API # # The following methods are required in alternative implementations of an - # applicaton queue, where a job is a [node, inputs] array: + # applicaton queue, where a job is a [task, input] array: # - # enq(node, inputs) # pushes the job onto the queue - # unshift(node, inputs) # unshifts the job onto the queue + # enq(task, input) # pushes the job onto the queue + # unshift(task, input) # unshifts the job onto the queue # deq # shifts a job off the queue # size # returns the number of jobs in the queue # clear # clears the queue, returns current jobs # synchronize # yields to the block # to_a # returns the queue as an array @@ -27,25 +27,24 @@ def initialize super @queue = [] end - # Enqueues the node and inputs as a job. - def enq(node, inputs) + # Enqueues the task and input. + def enq(task, input) synchronize do - @queue.push [node, inputs] + @queue.push [task, input] end end - # Enqueues the node and inputs, but to the top of the queue. - def unshift(node, inputs) + # Enqueues the task and input, but to the top of the queue. + def unshift(task, input) synchronize do - @queue.unshift [node, inputs] + @queue.unshift [task, input] end end - # Dequeues the next job as an array like [node, inputs]. Returns nil if - # the queue is empty. + # Dequeues the next job. Returns nil if the queue is empty. def deq synchronize { @queue.shift } end # Returns the number of enqueued jobs. \ No newline at end of file