grpc-rs
grpc-rs copied to clipboard
How to integrate with tokio/rust async IO ecosystem?
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.
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.
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.
Unless tokio allow integration with other executors, I don't think this can work smoothly. You have to spawn the future carefully.