Class: Hokusai::Automation::DriverCommandQueue

Inherits:
Object
  • Object
show all
Defined in:
ui/src/hokusai/automation/driver_command_queue.rb

Overview

A queue of ‘DriverCommand`

The queue is processed async on each iteration of the event loop

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDriverCommandQueue

Returns a new instance of DriverCommandQueue.



8
9
10
# File 'ui/src/hokusai/automation/driver_command_queue.rb', line 8

def initialize
  @commands = []
end

Instance Attribute Details

#commandsObject

Returns the value of attribute commands.



6
7
8
# File 'ui/src/hokusai/automation/driver_command_queue.rb', line 6

def commands
  @commands
end

Instance Method Details

#completed(results) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'ui/src/hokusai/automation/driver_command_queue.rb', line 12

def completed(results)
  if command = commands[0]
    # command was added in the middle of a render cycle, don't complete it.
    return if command.waiting?

    if value = command.on_complete
      case value
      when ::Hokusai::Automation::Error
        results[command.request_id] = [command, value]
      else
        results[command.request_id] = [command, value]
      end
    end

    if command.done?
      
      commands.shift
    end
  end
end

#process(blocks, canvas, input) ⇒ Object

Processes any availabe commands in the queue

Returns a Tuple containing the command and it’s wrapped return value



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'ui/src/hokusai/automation/driver_command_queue.rb', line 36

def process(blocks, canvas, input)
  return nil if commands.empty?

  command = commands[0]

  # wait for the start of the render loop
  # 
  # if there is no parent, execute the command
  return if !blocks[1].nil? && command.waiting?

  command.pending! if command.waiting?
  command.execute(blocks, canvas, input)
end