Class AsyncReaderConnection (2.22.0)

The *Connection object for AsyncReader.

Applications should have little need to use this class directly. They should use AsyncReader instead, which provides an easier to use interface.

In tests, this class can be used to mock the behavior of AsyncReader.

Functions

Cancel()

Cancels the current download.

Callers should continue reading until Read() is satisfied with a Status.

Returns
TypeDescription
void

Read()

Asks for more data.

An outcome with a Status indicates that no more data is available. Calling Read() after it returns a Status results in undefined behavior.

Applications should not have more than one Read() pending at a time. Calling Read() while a previous Read() is pending results in undefined behavior.

Applications should not destruct an AsyncReaderConnection until a call to Read() returns a Status response.

Retrieving more data can result in three outcomes:

  • Additional data (a ReadPayload) is available: in this case the future is satisfied with a ReadResponse containing a ReadPayload.
  • The download is interrupted with an error: in this case the future is satisfied with a ReadResponse containing a Status that describes the error.
  • The download has completed successfully: in this case the future is satisfied with a ReadResponse containing an OK Status.

A StatusOr<> cannot represent the last bullet point, so we need an absl::variant<> in this case. We could have used StatusOr<absl::optional<ReadPayload>> but that sounds unnecessarily complicated.

Returns
TypeDescription
future< ReadResponse >

GetRequestMetadata()

Return the request metadata.

Returns
TypeDescription
RpcMetadata

Type Aliases

ReadResponse

Alias Of: absl::variant< ReadPayload, Status >

The value returned by Read(). See the function for more details.