Class Tap::App::Queue
In: lib/tap/app/queue.rb
Parent: Monitor

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 [task, input] array:

  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

Note that synchronize must be implemented even if it does nothing but yield to the block.

Methods

clear   deq   enq   new   size   to_a   unshift  

Public Class methods

Creates a new Queue

[Source]

    # File lib/tap/app/queue.rb, line 27
27:       def initialize
28:         super
29:         @queue = []
30:       end

Public Instance methods

Clears self and returns an array of the currently enqueued jobs.

[Source]

    # File lib/tap/app/queue.rb, line 59
59:       def clear
60:         synchronize do
61:           current = @queue
62:           @queue = []
63:           current
64:         end
65:       end

Dequeues the next job. Returns nil if the queue is empty.

[Source]

    # File lib/tap/app/queue.rb, line 47
47:       def deq
48:         synchronize { @queue.shift }
49:       end

Enqueues the task and input.

[Source]

    # File lib/tap/app/queue.rb, line 33
33:       def enq(task, input)
34:         synchronize do
35:           @queue.push [task, input]
36:         end
37:       end

Returns the number of enqueued jobs.

[Source]

    # File lib/tap/app/queue.rb, line 52
52:       def size
53:         synchronize do
54:           @queue.size
55:         end
56:       end

Returns the enqueued jobs as an array.

[Source]

    # File lib/tap/app/queue.rb, line 68
68:       def to_a
69:         synchronize do
70:           @queue.dup
71:         end
72:       end

Enqueues the task and input, but to the top of the queue.

[Source]

    # File lib/tap/app/queue.rb, line 40
40:       def unshift(task, input)
41:         synchronize do
42:           @queue.unshift [task, input]
43:         end
44:       end

[Validate]