Sha256: 40ea1a1410e147199a1f676f6e862017bea3a3bf25ad540aad1d062d06ed1055
Contents?: true
Size: 1.28 KB
Versions: 33
Compression:
Stored size: 1.28 KB
Contents
# frozen_string_literal: true module Mutant class Timer include Concord.new(:process) # The now monotonic time # # @return [Float] def now process.clock_gettime(Process::CLOCK_MONOTONIC) end class Deadline include Anima.new(:timer, :allowed_time) def initialize(*arguments) super(*arguments) @start_at = timer.now end # Test if deadline is expired # # @return [Boolean] def expired? time_left <= 0 end # Deadline status snapshot class Status include Concord::Public.new(:time_left) # Test if deadline is not yet expired def ok? time_left.nil? || time_left.positive? end end # Status # Capture a deadline status # # @return [Status] def status Status.new(time_left) end # Probe the time left # # @return [Float, nil] def time_left allowed_time - (timer.now - @start_at) end # Deadline that never expires class None < self include Concord.new # The time left # # @return [Float, nil] def time_left; end def expired? false end end end # Deadline end # Timer end # Mutant
Version data entries
33 entries across 33 versions & 1 rubygems