Skip to content

Instantly share code, notes, and snippets.

@victorbrndls
Created June 1, 2021 00:26
Show Gist options
  • Save victorbrndls/2337c083239ce96030de375aefc69a83 to your computer and use it in GitHub Desktop.
Save victorbrndls/2337c083239ce96030de375aefc69a83 to your computer and use it in GitHub Desktop.
val scope = CoroutineScope(Dispatchers.IO)
fun main() {
val channel = AndroidChannelBuilder
.forAddress("127.0.0.1", 9090)
.build()
val book = BookOuterClass.Book.newBuilder()
.setId(1)
.setTitle("gRPC In-Depth")
.build()
val createBookRequest = BookOuterClass.CreateBookRequest.newBuilder()
.setBook(book)
.build()
val stub = BookstoreGrpcKt.BookstoreCoroutineStub(channel)
scope.launch {
try {
stub.createBook(createBookRequest)
} catch (e: StatusException) {
// handle exception
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment