Sha256: 4351239647fb47ae9e798d08f6ff051f792d46fd93f6f0b9f2836aad6f8540c1

Contents?: true

Size: 1.38 KB

Versions: 25

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true
module Dynflow
  module Testing
    class DummyExecutor
      attr_reader :world, :events_to_process

      def initialize(world)
        @world             = world
        @events_to_process = []
      end

      def event(execution_plan_id, step_id, event, future = Concurrent::Promises.resolvable_future)
        @events_to_process << [execution_plan_id, step_id, event, future]
      end

      def delayed_event(director_event)
        @events_to_process << [director_event.execution_plan_id, director_event.step_id, director_event.event, director_event.result]
      end

      def plan_events(delayed_events)
        delayed_events.each do |event|
          world.plan_event(event.execution_plan_id, event.step_id, event.event, event.time)
        end
      end

      def execute(action, event = nil)
        action.execute event
        plan_events(action.delayed_events.dup)
        action.delayed_events.clear
      end

      # returns true if some event was processed.
      def progress
        events = @events_to_process.dup
        clear
        events.each do |execution_plan_id, step_id, event, future|
          future.fulfill true
          if event && world.action.state != :suspended
            return false
          end
          execute(world.action, event)
        end
      end

      def clear
        @events_to_process.clear
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
dynflow-1.8.2 lib/dynflow/testing/dummy_executor.rb
dynflow-1.8.1 lib/dynflow/testing/dummy_executor.rb
dynflow-1.8.0 lib/dynflow/testing/dummy_executor.rb
dynflow-1.7.0 lib/dynflow/testing/dummy_executor.rb
dynflow-1.6.11 lib/dynflow/testing/dummy_executor.rb
dynflow-1.6.10 lib/dynflow/testing/dummy_executor.rb
dynflow-1.6.8 lib/dynflow/testing/dummy_executor.rb
dynflow-1.6.7 lib/dynflow/testing/dummy_executor.rb
dynflow-1.6.6 lib/dynflow/testing/dummy_executor.rb
dynflow-1.6.5 lib/dynflow/testing/dummy_executor.rb
dynflow-1.6.4 lib/dynflow/testing/dummy_executor.rb
dynflow-1.6.3 lib/dynflow/testing/dummy_executor.rb
dynflow-1.6.2 lib/dynflow/testing/dummy_executor.rb
dynflow-1.6.1 lib/dynflow/testing/dummy_executor.rb
dynflow-1.4.9 lib/dynflow/testing/dummy_executor.rb
dynflow-1.4.8 lib/dynflow/testing/dummy_executor.rb
dynflow-1.5.0 lib/dynflow/testing/dummy_executor.rb
dynflow-1.4.7 lib/dynflow/testing/dummy_executor.rb
dynflow-1.4.6 lib/dynflow/testing/dummy_executor.rb
dynflow-1.4.5 lib/dynflow/testing/dummy_executor.rb