Grpc Streaming Call
fun <S : Any, R : Any> GrpcStreamingCall(function: suspend (ReceiveChannel<S>, SendChannel<R>) -> Unit): GrpcStreamingCall<S, R>
Returns a new instance of GrpcStreamingCall that can be used for a single call to executeIn or executeBlocking.
The returned instance launches function on Dispatchers.IO. The function must close the SendChannel when it has no more messages to transmit. If function throws, both channels will be closed using the thrown exception as a cause.
This method is useful when implementing the interfaces that are generated by Wire:
override fun RouteChat(): GrpcStreamingCall<RouteNote, RouteNote> {
return GrpcStreamingCall { requests, responses ->
requests.consumeEach { note ->
responses.send(translateNote(note))
}
responses.close()
}
}
Content copied to clipboard
It is succinct when used in an expression function:
override fun RouteChat() = GrpcStreamingCall<RouteNote, RouteNote> { requests, responses ->
requests.consumeEach { note ->
responses.send(translateNote(note))
}
responses.close()
}
Content copied to clipboard