Module: GRPC::Core::TimeConsts

Included in:
ActiveCall, BidiCall, GRPC::ClientStub, RpcServer
Defined in:
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 '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