When exactly does hyper::client::request do the job?


#1

I am using hyper::client::Client::request method. The documentation for the method tells: Send a constructed Request using this Client. But I wonder when does it issue bytes to the network: when the function is called or when the returned result future is polled?


#2

If I understand it correctly, the method will probably send the first bytes to initiate the connection if it’s available, but likely won’t send the rest until it’s polled. It might also wait if there are more connections to the same server on the same client that might want to be reused.

It might initiate a connection immediately, but in any case it definitely won’t “finish” the connection without being polled. It works on the tokio runtime, and futures are not meant to be left alone- the whole system works by having tokio “in control” of a thread which is mostly IO-bound.

In short: it will send some of the bytes, but not enough to be useful. Definitely tokio::run() the future or combine it with other futures and then run the combination.


#3

Thanks!