Class: Tap::Support::ExecutableQueue

Inherits:
Object
  • Object
show all
Includes:
MonitorMixin
Defined in:
lib/tap/support/executable_queue.rb

Overview

ExecutableQueue allows thread-safe enqueing and dequeing of Executable methods and inputs for execution.

Instance Method Summary collapse

Constructor Details

#initializeExecutableQueue

Creates a new ExecutableQueue



10
11
12
13
14
# File 'lib/tap/support/executable_queue.rb', line 10

def initialize
  # required for MonitorMixin
  super()
  @queue = []
end

Instance Method Details

#clearObject

Clears all methods and inputs. Returns the existing queue as an array.



17
18
19
20
21
22
23
# File 'lib/tap/support/executable_queue.rb', line 17

def clear
  synchronize do
    current = self.queue
    self.queue = []
    current
  end
end

#concat(array) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/tap/support/executable_queue.rb', line 59

def concat(array)
  synchronize do
    array.each do |method, inputs|
      enq(method, inputs)
    end
  end
end

#deqObject

Dequeues the next method and inputs as an array like [method, inputs]. Returns nil if the queue is empty.



55
56
57
# File 'lib/tap/support/executable_queue.rb', line 55

def deq
  synchronize { queue.shift }
end

#empty?Boolean

True if no methods are enqueued

Returns:

  • (Boolean)


31
32
33
# File 'lib/tap/support/executable_queue.rb', line 31

def empty?
  queue.empty?
end

#enq(method, inputs) ⇒ Object

Enqueues the method and inputs. Raises an error if the

method is not an Executable.



37
38
39
40
41
42
# File 'lib/tap/support/executable_queue.rb', line 37

def enq(method, inputs)
  synchronize do
    check_method(method)
    queue.push [method, inputs]
  end
end

#sizeObject

Returns the number of enqueued methods



26
27
28
# File 'lib/tap/support/executable_queue.rb', line 26

def size
  queue.length
end

#to_aObject

Converts self to an array.



68
69
70
# File 'lib/tap/support/executable_queue.rb', line 68

def to_a
  queue.dup
end

#unshift(method, inputs) ⇒ Object

Enqueues the method and inputs, but to the top of the queue. Raises an error if the method is not an Executable.



46
47
48
49
50
51
# File 'lib/tap/support/executable_queue.rb', line 46

def unshift(method, inputs)
  synchronize do
    check_method(method)
    queue.unshift [method, inputs]
  end
end