grpc-rs icon indicating copy to clipboard operation
grpc-rs copied to clipboard

How to integrate with tokio/rust async IO ecosystem?

Open vimpunk opened this issue 6 years ago • 3 comments

I'm wondering how to integrate grpc-rs with the futures/tokio ecosystem on stable rust. As far as I understand grpc-rs uses the IO reactor of grpc-core, so there isn't a way to drive futures to completion on the tokio reactor used for other things in rust. Is this correct? If so, how would you chain futures of grpc-rs and other async IO stuff using tokio?

Thanks in advance for the help.

vimpunk avatar Jun 28 '19 14:06 vimpunk

I'm using latest master branch of tokio with grpc-rs. grpc client can drive its stream receiver and send it out through mpsc channel's sender, then the other side can be processed by tokio reactor. Again, with a mpsc channel (futures 0.1 since grpc is not using the newly updated std::future) can pump data into grpc's sink. It works with futures 0.3's compat features too.

another-s347 avatar Jul 18 '19 14:07 another-s347

I use following setup:

futures = "0.3"
tokio = { version = "0.2", features = ["sync", "macros", "rt-threaded", "time", "fs"] }
grpcio = { version = "0.6", features = ["openssl"] }

I can confirm that mpsc channel sender works (although I suspect that's because sending a message is not actually a future), async mutex works, as well, but fs doesn't. tokio::fs::write produces following panic:

grpc-poll-0' panicked at 'not currently running on the Tokio runtime.

porkbrain avatar Aug 05 '20 00:08 porkbrain

Unless tokio allow integration with other executors, I don't think this can work smoothly. You have to spawn the future carefully.

BusyJay avatar Aug 05 '20 07:08 BusyJay