A convenience class representing a single moment in monotonic time. Returned by {Concurrent::Channel} tickers and timers when they resolve.
Includes `Comparable` and can be compared to monotonic_time, UTC time, or epoch time.
@see Concurrent.monotonic_time @see Concurrent::Channel.ticker @see Concurrent::Channel.timer
# File lib/concurrent/channel/tick.rb, line 25 def initialize(tick = Concurrent.monotonic_time) @monotonic = tick @utc = monotonic_to_utc(tick).freeze end
# File lib/concurrent/channel/tick.rb, line 38 def <=>(other) if other.is_a? Numeric @monotonic <=> other elsif other.is_a? Time @utc <=> other.utc elsif other.is_a? Tick @monotonic <=> other.monotonic else nil end end
# File lib/concurrent/channel/tick.rb, line 30 def epoch @utc.to_f end
# File lib/concurrent/channel/tick.rb, line 34 def to_s @utc.strftime(STRING_FORMAT) end
# File lib/concurrent/channel/tick.rb, line 52 def monotonic_to_utc(tick) Time.now.utc + Concurrent.monotonic_time - tick end