class Concurrent::Channel::Tick
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
Constants
- STRING_FORMAT
Attributes
monotonic[R]
utc[R]
Public Class Methods
new(tick = Concurrent.monotonic_time)
click to toggle source
# File lib/concurrent/channel/tick.rb, line 25 def initialize(tick = Concurrent.monotonic_time) @monotonic = tick @utc = monotonic_to_utc(tick).freeze end
Public Instance Methods
<=>(other)
click to toggle source
# 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
epoch()
click to toggle source
# File lib/concurrent/channel/tick.rb, line 30 def epoch @utc.to_f end
to_s()
click to toggle source
# File lib/concurrent/channel/tick.rb, line 34 def to_s @utc.strftime(STRING_FORMAT) end
Private Instance Methods
monotonic_to_utc(tick)
click to toggle source
# File lib/concurrent/channel/tick.rb, line 52 def monotonic_to_utc(tick) Time.now.utc + Concurrent.monotonic_time - tick end