Functions

getDeadline
I

Returns the deadline value as time:Utc.

getHeader
I

Returns the header value with the specified header name.

getHeaders
I

Gets all the transport headers with the specified header name.

isCancelled
I

Checks whether the deadline is already exceeded or not.

setDeadline
I

Enables the deadline by adding the deadline header to the given headers.

getDeadline

function getDeadline(map<string | string[ ]> headerMap) returns Utc? | Error
Isolated Function

Returns the deadline value as time:Utc. This can be used to get the deadline and propagate it to subsequent internal calls.

1time:Utc?|time:Error deadline = grpc:getDeadline(map<string|string[]> headerMap);

Parameters

Return Type

(Utc? | Error)

deadline value when the deadline is correctly specified, () when the deadline is not specified, or else a time:Error when a deadline-parsing error occurred

getHeader

function getHeader(map<string | string[ ]> headerMap, string headerName) returns string | Error
Isolated Function

Returns the header value with the specified header name. If there are more than one header values for the specified header name, the first value is returned.

1map<string|string[]> headerMap = request.headers;
2string|grpc:Error result = grpc:getHeader(headerMap, "content-type");

Parameters

  • headerName string
  • The header name

Return Type

(string | Error)

First header value if exists or else error

getHeaders

function getHeaders(map<string | string[ ]> headerMap, string headerName) returns string[ ] | Error
Isolated Function

Gets all the transport headers with the specified header name.

1map<string|string[]> headerMap = request.headers;
2string[]|grpc:Error result = grpc:getHeaders(headerMap, "content-type");

Parameters

  • headerName string
  • The header name

Return Type

(string[ ] | Error)

Header value array

isCancelled

function isCancelled(map<string | string[ ]> headerMap) returns boolean | Error
Isolated Function

Checks whether the deadline is already exceeded or not.

1boolean|time:Error isCancelled = grpc:isCancelled(map<string|string[]> headerMap);

Parameters

Return Type

(boolean | Error)

true when the deadline is exceeded, false when the deadline is not exceeded, or else a time:Error when a deadline-parsing error occurred

setDeadline

function setDeadline(Utc deadline, map<string | string[ ]> headerMap) returns map<string | string[ ]>
Isolated Function

Enables the deadline by adding the deadline header to the given headers.

1time:Utc current = time:utcNow();
2time:Utc deadline = time:utcAddSeconds(current, 300);
3map<string|string[]> headers = grpc:setDeadline(deadline);

Parameters

  • deadline Utc
  • The deadline time value (this should be a specific time and not a duration)

  • headerMap map<string | string[ ]> (default {})
  • Optional header map (if this is not specified, it creates a new header set)

Return Type

(map<string | string[ ]>)

The header map that includes the deadline