Module: RuneRb::Game::World::Pipeline

Included in:
Instance
Defined in:
app/game/world/helpers/pipeline.rb

Overview

Since:

  • 0.9.3

Instance Method Summary collapse

Instance Method Details

#post(params, &action) ⇒ Object

Adds a job to be performed in the pipeline

Parameters:

  • params (Hash)

    parameters for the posted Action.

  • action (Proc)

    work to be performed during the Action's execution.

Since:

  • 0.9.3


34
35
36
# File 'app/game/world/helpers/pipeline.rb', line 34

def post(params, &action)
  @stack << RuneRb::Game::World::Action.new(params) { action.call(params[:assets]) }
end

#start_pipelineObject

Begins executing Actions in the <@stack>.

Since:

  • 0.9.3


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/game/world/helpers/pipeline.rb', line 4

def start_pipeline
  # Execute pending actions
  unless @stack.empty?
    begin
      log! "#{@stack.size} Actions in stack"

      # Call the <=> function on each item in the collection and arrange them in an descending order.
      @stack.sort!

      # Update each Action#target to point to the next member of <@stack>
      @stack.each do |action|
        break if action.nil? || action == @stack.last

        action.target_to(@stack[@stack.index(action) + 1].start(auto: false))
      end

      # Start the first action.
      @stack.first.start(auto: true)

      @stack.clear
    rescue StandardError => e
      err "An error occurred while processing Jobs! Halted at Job with ID: #{@stack&.first&.id}", @stack&.first&.inspect, e
      err e.backtrace&.join("\n")
    end
  end
end