Module: GRPC::Core::TimeConsts

Included in:
Etcdv3::Auth, Etcdv3::KV, Etcdv3::Lease, Etcdv3::Lock, Etcdv3::Namespace::KV, Etcdv3::Namespace::Lock, Etcdv3::Namespace::Watch, Etcdv3::Watch, ActiveCall, BidiCall, GRPC::ClientStub, RpcServer
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/grpc-1.50.0-x86_64-linux/src/ruby/lib/grpc/core/time_consts.rb

Overview

TimeConsts is a module from the C extension.

Here it’s re-opened to add a utility func.

Class Method Summary collapse

Class Method Details

.from_relative_time(timeish) ⇒ Number|TimeSpec

Converts a time delta to an absolute deadline.

Assumes timeish is a relative time, and converts its to an absolute, with following exceptions:

  • if timish is one of the TimeConsts.TimeSpec constants the value is

preserved.

  • timish < 0 => TimeConsts.INFINITE_FUTURE

  • timish == 0 => TimeConsts.ZERO

Parameters:

  • timeish (Number|TimeSpec)

Returns:

  • (Number|TimeSpec)


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/grpc-1.50.0-x86_64-linux/src/ruby/lib/grpc/core/time_consts.rb', line 36

def from_relative_time(timeish)
  if timeish.is_a? TimeSpec
    timeish
  elsif timeish.nil?
    TimeConsts::ZERO
  elsif !timeish.is_a? Numeric
    fail(TypeError,
         "Cannot make an absolute deadline from #{timeish.inspect}")
  elsif timeish < 0
    TimeConsts::INFINITE_FUTURE
  elsif timeish.zero?
    TimeConsts::ZERO
  else
    Time.now + timeish
  end
end