livery_grpc_timeout (livery_grpc v0.1.1)

View Source

The grpc-timeout header: a call deadline on the wire.

The value is an ASCII integer (up to 8 digits) followed by a unit: H hours, M minutes, S seconds, m milliseconds, u microseconds, n nanoseconds. This module converts between that wire form and a millisecond timeout (the unit Erlang's receive ... after and timers use). Sub-millisecond units round up to 1 ms so a deadline is never 0.

Summary

Functions

Encode a millisecond timeout as a grpc-timeout value. infinity returns undefined (no header). Values that fit in 8 digits of milliseconds use the m unit; larger deadlines fall back to whole seconds.

Parse a grpc-timeout value into milliseconds. undefined (header absent) yields infinity. A malformed value also yields infinity, so a bad header relaxes the deadline rather than failing the call.

Functions

encode/1

-spec encode(timeout()) -> binary() | undefined.

Encode a millisecond timeout as a grpc-timeout value. infinity returns undefined (no header). Values that fit in 8 digits of milliseconds use the m unit; larger deadlines fall back to whole seconds.

parse/1

-spec parse(binary() | undefined) -> timeout().

Parse a grpc-timeout value into milliseconds. undefined (header absent) yields infinity. A malformed value also yields infinity, so a bad header relaxes the deadline rather than failing the call.