Class List Method List File List

# Class: Concurrent::Channel::Tick

Inherits:
  Synchronization::Object
  - Object
  - Synchronization::Object
  - Concurrent::Channel::Tick
  show all
Includes:
  Comparable
Defined in:
  lib/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.

See Also:

- Concurrent.monotonic_time
- ticker
- timer

## Constant Summary

STRING_FORMAT =

      '%F %T.%6N %z %Z'.freeze

## Instance Attribute Summary (collapse)

- - (undocumented) monotonic readonly

  Returns the value of attribute monotonic.

- - (undocumented) utc readonly

  Returns the value of attribute utc.

## Instance Method Summary (collapse)

- - (undocumented) <=>(other)
- - (undocumented) epoch
- - (Tick) initialize(tick = Concurrent.monotonic_time) constructor

  A new instance of Tick.

- - (undocumented) to_s

## Constructor Details

### - (`Tick`) initialize(tick = Concurrent.monotonic_time)

Returns a new instance of Tick

    25
    26
    27
    28

    # File 'lib/concurrent/channel/tick.rb', line 25

    def initialize(tick = Concurrent.monotonic_time)
      @monotonic = tick
      @utc = monotonic_to_utc(tick).freeze
    end

## Instance Attribute Details

### - (`undocumented`) monotonic (readonly)

Returns the value of attribute monotonic

    23
    24
    25

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

    def monotonic
      @monotonic
    end

### - (`undocumented`) utc (readonly)

Returns the value of attribute utc

    23
    24
    25

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

    def utc
      @utc
    end

## Instance Method Details

### - (`undocumented`) <=>(other)

    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48

    # 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

### - (`undocumented`) epoch

    30
    31
    32

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

    def epoch
      @utc.to_f
    end

### - (`undocumented`) to_s

    34
    35
    36

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

    def to_s
      @utc.strftime(STRING_FORMAT)
    end