Sha256: ebcf71ca16dee781edca0e6795529a21a86a64cdb119ec1b87524de116432801

Contents?: true

Size: 892 Bytes

Versions: 11

Compression:

Stored size: 892 Bytes

Contents

module Dynflow
  module Testing
    class ManagedClock

      attr_reader :pending_pings

      include Algebrick::Types
      Timer = Algebrick.type do
        fields! who:   Object, # to ping back
                when:  type { variants Time, Numeric }, # to deliver
                what:  Maybe[Object], # to send
                where: Symbol # it should be delivered, which method
      end

      module Timer
        include Clock::Timer
      end

      def initialize
        @pending_pings = []
      end

      def ping(who, time, with_what = nil, where = :<<)
        with = with_what.nil? ? None : Some[Object][with_what]
        @pending_pings << Timer[who, time, with, where]
      end

      def progress
        copy = @pending_pings.dup
        clear
        copy.each { |ping| ping.apply }
      end

      def clear
        @pending_pings.clear
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
dynflow-0.7.7 lib/dynflow/testing/managed_clock.rb
dynflow-0.7.6 lib/dynflow/testing/managed_clock.rb
dynflow-0.7.5 lib/dynflow/testing/managed_clock.rb
dynflow-0.7.4 lib/dynflow/testing/managed_clock.rb
dynflow-0.7.3 lib/dynflow/testing/managed_clock.rb
dynflow-0.7.2 lib/dynflow/testing/managed_clock.rb
dynflow-0.7.1 lib/dynflow/testing/managed_clock.rb
dynflow-0.7.0 lib/dynflow/testing/managed_clock.rb
dynflow-0.6.2 lib/dynflow/testing/managed_clock.rb
dynflow-0.6.1 lib/dynflow/testing/managed_clock.rb
dynflow-0.6.0 lib/dynflow/testing/managed_clock.rb