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