class Timeout
The grpc-timeout header represents the gRPC request timeout.
The grpc-timeout header specifies how long the client is willing to wait for an RPC to complete.
The format is: value + unit (H=hours, M=minutes, S=seconds, m=milliseconds, u=microseconds, n=nanoseconds).
This header appears only in request headers, not in trailers.
Definitions
def self.parse(value)
Parse a timeout from a header value.
Signature
-
parameter
valueString The header value to parse (e.g., "5S", "1000m").
-
returns
Timeout A new Timeout instance.
Implementation
def self.parse(value)
new(value)
end
def self.coerce(value)
Coerce a value to a Timeout instance.
If a Numeric is provided, it will be formatted as a gRPC timeout string using Protocol::GRPC::Methods.format_timeout.
Signature
-
parameter
valueString | Numeric The value to coerce.
-
returns
Timeout A new Timeout instance.
Implementation
def self.coerce(value)
if value.is_a?(Numeric)
return new(Protocol::GRPC::Methods.format_timeout(value))
else
return new(value.to_s)
end
end
def initialize(value)
Initialize the timeout header with the given value.
Signature
-
parameter
valueString The timeout value in gRPC format.
Implementation
def initialize(value)
super(value.to_s)
end
def to_seconds
Parse the timeout value to seconds.
Signature
-
returns
Numeric | Nil Timeout in seconds, or
Nilif value is invalid.
Implementation
def to_seconds
Protocol::GRPC::Methods.parse_timeout(self)
end
def <<(value)
Merge another timeout value (takes the new value, as timeout should only appear once)
Signature
-
parameter
valueString The new timeout value
Implementation
def <<(value)
replace(value.to_s)
return self
end
def self.trailer?
Whether this header is acceptable in HTTP trailers.
The grpc-timeout header is request-only and does not appear in trailers.
Signature
-
returns
Boolean false, as grpc-timeout cannot appear in trailers.
Implementation
def self.trailer?
false
end