123456789_123456789_123456789_123456789_123456789_

Class: Concurrent::Channel::Tick

Overview

A convenience class representing a single moment in monotonic time. Returned by Channel tickers and timers when they resolve.

Includes Comparable and can be compared to monotonic_time, UTC time, or epoch time.

Constant Summary

Class Attribute Summary

Class Method Summary

Synchronization::Object - Inherited

.atomic_attribute?, .atomic_attributes,
.attr_atomic

Creates methods for reading and writing to a instance variable with volatile (Java) semantic as .attr_volatile does.

.attr_volatile

Creates methods for reading and writing (as attr_accessor does) to a instance variable with volatile (Java) semantic.

.ensure_safe_initialization_when_final_fields_are_present

For testing purposes, quite slow.

.new

Has to be called by children.

.safe_initialization!, .define_initialize_atomic_fields

Synchronization::AbstractObject - Inherited

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(tick = Concurrent.monotonic_time) ⇒ Tick

[ GitHub ]

  
# 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 (readonly)

[ GitHub ]

  
# File 'lib/concurrent-ruby-edge/concurrent/channel/tick.rb', line 23

attr_reader :monotonic, :utc

#utc (readonly)

[ GitHub ]

  
# File 'lib/concurrent-ruby-edge/concurrent/channel/tick.rb', line 23

attr_reader :monotonic, :utc

Instance Method Details

#<=>(other)

[ GitHub ]

  
# 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

[ GitHub ]

  
# File 'lib/concurrent-ruby-edge/concurrent/channel/tick.rb', line 30

def epoch
  @utc.to_f
end

#monotonic_to_utc(tick) (private)

[ GitHub ]

  
# File 'lib/concurrent-ruby-edge/concurrent/channel/tick.rb', line 52

def monotonic_to_utc(tick)
  Time.now.utc + Concurrent.monotonic_time - tick
end

#to_s

[ GitHub ]

  
# File 'lib/concurrent-ruby-edge/concurrent/channel/tick.rb', line 34

def to_s
  @utc.strftime(STRING_FORMAT)
end