Repository navigation
How to implement hyper request timeout #2449
Answered
by
davidbarsky
kushwahashiv
asked this question in
Q&A
|
Hi All I'm facing hyper request timeout implement/migration issue. earlier implementation is similar to below Now I am not sure what is the best practice to implement request timeout using futures and tokio. Any link or help will be appreciated. I tried finding but could not find one. Thanks in advance. /Shiv |
Answered by
davidbarsky
Mar 1, 2021
Replies: 2 comments 2 replies
|
Does something like this help? use hyper::{Client, Uri};
use tokio::time::timeout;
use std::time::Duration;
#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
let client = Client::new();
let future = client.get(Uri::from_static("http://httpbin.org/ip"));
match timeout(Duration::from_millis(30), future).await {
Ok(_) => println!("Got response"),
Err(_) => println!("timed out"),
};
Ok(())
} |
2 replies
Answer selected by
kushwahashiv
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does something like this help?