简体   繁体   English

GRPC 未来与客户端中的阻塞存根

[英]GRPC future vs blocking stub in client

I'm writing a client application in Kotlin where I need to call a GRPC service that has both a future based and a blocking stub.我正在 Kotlin 中编写一个客户端应用程序,我需要调用一个 GRPC 服务,该服务同时具有基于未来和阻塞的存根。

In case I choose to go with the future option, I will need at some point to do something like a CompletableFuture.get() call, which means I will be blocking anyway.如果我选择带有 future 选项的 go,我将需要在某个时候执行类似CompletableFuture.get()调用的操作,这意味着我无论如何都会阻塞。

So, what's the difference between one and the other for this case?那么,在这种情况下,两者之间有什么区别? Or is it the same?或者是一样的?

I will need at some point to do something like a CompletableFuture.get() call, which means I will be blocking anyway在某些时候我需要做一些类似 CompletableFuture.get() 调用的事情,这意味着我无论如何都会阻塞

Not necessarily.不必要。 With a ListenableFuture , CompletableFuture , or other completion-hookable mechanisms, you don't have to block at all.使用ListenableFutureCompletableFuture或其他完成挂钩机制,您根本不必阻塞。 You could register an action to do on completion, or you could wrap them in suspend calls to work with coroutines etc.您可以注册一个在完成时执行的操作,或者您可以将它们包装在suspend调用中以使用协程等。

Also, even if you did call get() and block, it still allows you to block later than the start of the call, and do other things between the initial call and the get() , which would be concurrent with it:此外,即使您确实调用了get()并阻塞,它仍然允许您在调用开始之后阻塞,并在初始调用和get()之间做其他事情,这将与它并发:

val future = callSomethingWithFuture()
doStuffConcurrently()
val result = future.get()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 取消订阅异步grpc存根中的观察器-Java / Kotlin - Unsubscribe observer in Async grpc stub - Java / Kotlin 如何在客户端 gRPC 中使用 Wire 和 Flow? - How use Wire with Flow in client gRPC? 如何为 Android 客户端在 Kotlin 上使用 protobuf 生成 gRPC 代码? - How to generate gRPC code with protobuf on Kotlin for Android client? 如何使具有服务器流连接的 Android grpc 客户端保持活动状态? - How to keep an Android grpc client with server streaming connection alive? GRPC Okhttp android 客户端通道,带有自签名 ssl 证书 - GRPC Okhttp android client channel with self signed ssl certificate 如何使用阻止客户端和协程的改造来实施受限呼叫 - how to implement a limited call with retrofit blocking client and coroutines 异步垂直与复合未来垂直。 它们有何不同? - Async Verticle vs Composite Future Verticle. How are they different? 如何将 OpenAPI 生成器 retrofit 存根与 android kotlin 客户端一起使用? 响应 501“未实施” - How to use the OpenAPI generators retrofit stub with android kotlin client? Response 501 "Not Implemented" DialogFlow Android SDK 需要 grpc-okhttp,但添加它会导致 Socket IO 客户端崩溃 - DialogFlow Android SDK needs grpc-okhttp, but adding it resulting to crashing of Socket IO CLient GRPC 客户端 - Http2Exception:第一个接收到的帧不是 SETTINGS。 前 5 个字节的十六进制转储:485454502f - GRPC Client - Http2Exception: First received frame was not SETTINGS. Hex dump for first 5 bytes: 485454502f
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM