Class: Concurrent::Channel::Tick
- Inherits:
-
Synchronization::Object
- Object
- Synchronization::Object
- Concurrent::Channel::Tick
- Includes:
- Comparable
- Defined in:
- lib-edge/concurrent/channel/tick.rb
Overview
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.
Constant Summary collapse
- STRING_FORMAT =
'%F %T.%6N %z %Z'.freeze
Instance Attribute Summary collapse
- #monotonic ⇒ undocumented readonly
- #utc ⇒ undocumented readonly
Instance Method Summary collapse
- #<=>(other) ⇒ undocumented
- #epoch ⇒ undocumented
-
#initialize(tick = Concurrent.monotonic_time) ⇒ Tick
constructor
A new instance of Tick.
- #to_s ⇒ undocumented
Constructor Details
#initialize(tick = Concurrent.monotonic_time) ⇒ Tick
Returns a new instance of Tick.
25 26 27 28 |
# File 'lib-edge/concurrent/channel/tick.rb', line 25 def initialize(tick = Concurrent.monotonic_time) @monotonic = tick @utc = monotonic_to_utc(tick).freeze end |
Instance Attribute Details
#monotonic ⇒ undocumented (readonly)
23 24 25 |
# File 'lib-edge/concurrent/channel/tick.rb', line 23 def monotonic @monotonic end |
#utc ⇒ undocumented (readonly)
23 24 25 |
# File 'lib-edge/concurrent/channel/tick.rb', line 23 def utc @utc end |
Instance Method Details
#<=>(other) ⇒ undocumented
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib-edge/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 ⇒ undocumented
30 31 32 |
# File 'lib-edge/concurrent/channel/tick.rb', line 30 def epoch @utc.to_f end |
#to_s ⇒ undocumented
34 35 36 |
# File 'lib-edge/concurrent/channel/tick.rb', line 34 def to_s @utc.strftime(STRING_FORMAT) end |