Module: GRPC::Core::TimeConsts
- Included in:
- ActiveCall, BidiCall, RpcServer
- Defined in:
- 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
-
.from_relative_time(timeish) ⇒ Object
Converts a time delta to an absolute deadline.
Class Method Details
.from_relative_time(timeish) ⇒ Object
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
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/grpc/core/time_consts.rb', line 51 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 == 0 TimeConsts::ZERO else Time.now + timeish end end |