GrpcStreamingCall

interface GrpcStreamingCall<S : Any, R : Any>

A single streaming call to a remote server. This class handles three streaming call types:

  • Single request, streaming response. The send channel or message sink accept exactly one message. The receive channel or message source produce zero or more messages. The outbound request message is sent before any inbound response messages.

  • Streaming request, single response. The send channel or message sink accept zero or more messages. The receive channel or message source produce exactly one message. All outbound request messages are sent before the inbound response message.

  • Streaming request, streaming response. The send channel or message sink accept zero or more messages, and the receive channel or message source produce any number of messages. Unlike the above two types, you are free to interleave request and response messages.

A gRPC call cannot be executed twice.

gRPC calls can be suspending or blocking. Use whichever mechanism works at your call site: the bytes transmitted on the network are the same.

Properties

Link copied to clipboard
abstract val method: GrpcMethod<S, R>

The method invoked by this call.

Link copied to clipboard

A map containing request metadata. This is initially empty; it can be assigned to any other map of metadata before the call is executed. It is an error to set this value after the call is executed.

Link copied to clipboard

A map containing response metadata. This is null until the call has executed, at which point it will be non-null if the call completed successfully. It may also be non-null in failure cases if the failure was not a problem of connectivity. For example, if the gRPC call fails with an HTTP 503 error, response metadata will be present.

Link copied to clipboard
abstract val timeout: Timeout

Configures how long the call can take to complete before it is automatically canceled. The timeout applies to the full set of messages transmitted. For long-running streams you must configure a sufficiently long timeout.

Functions

Link copied to clipboard
abstract fun cancel()

Attempts to cancel the call. This function is safe to call concurrently with execution. When canceled, execution fails with an immediate IOException rather than waiting to complete normally.

Link copied to clipboard
abstract fun clone(): GrpcStreamingCall<S, R>

Create a new, identical gRPC call to this one which can be enqueued or executed even if this call has already been.

Link copied to clipboard
abstract fun executeBlocking(): Pair<MessageSink<S>, MessageSource<R>>

Enqueues this call for execution and returns streams to send and receive the call's messages. Reads and writes on the returned streams are blocking.

Link copied to clipboard
abstract fun executeIn(scope: CoroutineScope): Pair<SendChannel<S>, ReceiveChannel<R>>

Enqueues this call for execution and returns channels to send and receive the call's messages. This uses the Dispatchers.IO to transmit outbound messages.

Link copied to clipboard
abstract fun isCanceled(): Boolean

True if cancel was called.

Link copied to clipboard
abstract fun isExecuted(): Boolean

Returns true if executeIn or executeBlocking was called. It is an error to execute a call more than once.