Sha256: ba60de5d2f673b2ce9d8fef2bb93e19387c6df01bdd15815beabec3e715d3664

Contents?: true

Size: 1.1 KB

Versions: 24

Compression:

Stored size: 1.1 KB

Contents

module Dynflow
  module Testing
    class ManagedClock

      attr_reader :pending_pings

      include Algebrick::Types

      def initialize
        @pending_pings = []
      end

      def ping(who, time, with_what = nil, where = :<<)
        time = current_time + time if time.is_a? Numeric
        with = with_what.nil? ? None : Some[Object][with_what]
        @pending_pings << Clock::Timer[who, time, with, where]
        @pending_pings.sort!
      end

      def progress(ignored_subjects = [])
        if next_ping = @pending_pings.shift
          if !next_ping.what.respond_to?(:value) || !ignored_subjects.include?(next_ping.what.value)
            # we are testing an isolated system = we can move in time
            # without actually waiting
            @current_time = next_ping.when
            next_ping.apply
          end
        end
      end

      def progress_all(ignored_subjects = [])
        progress(ignored_subjects) until @pending_pings.empty?
      end

      def current_time
        @current_time ||= Time.now
      end

      def clear
        @pending_pings.clear
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
dynflow-1.3.0 lib/dynflow/testing/managed_clock.rb
dynflow-1.2.3 lib/dynflow/testing/managed_clock.rb
dynflow-1.2.2 lib/dynflow/testing/managed_clock.rb
dynflow-1.2.1 lib/dynflow/testing/managed_clock.rb
dynflow-1.2.0 lib/dynflow/testing/managed_clock.rb
dynflow-1.2.0.pre1 lib/dynflow/testing/managed_clock.rb
dynflow-1.1.6 lib/dynflow/testing/managed_clock.rb
dynflow-1.1.5 lib/dynflow/testing/managed_clock.rb
dynflow-1.1.4 lib/dynflow/testing/managed_clock.rb
dynflow-1.1.3 lib/dynflow/testing/managed_clock.rb
dynflow-1.1.2 lib/dynflow/testing/managed_clock.rb
dynflow-1.1.1 lib/dynflow/testing/managed_clock.rb
dynflow-1.1.0 lib/dynflow/testing/managed_clock.rb
dynflow-1.0.5 lib/dynflow/testing/managed_clock.rb
dynflow-1.0.4 lib/dynflow/testing/managed_clock.rb
dynflow-1.0.3 lib/dynflow/testing/managed_clock.rb
dynflow-1.0.2 lib/dynflow/testing/managed_clock.rb
dynflow-1.0.1 lib/dynflow/testing/managed_clock.rb
dynflow-1.0.0 lib/dynflow/testing/managed_clock.rb
dynflow-0.8.37 lib/dynflow/testing/managed_clock.rb