Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to implement hyper request timeout #2448

Closed
kushwahashiv opened this issue Mar 1, 2021 · 1 comment
Closed

How to implement hyper request timeout #2448

kushwahashiv opened this issue Mar 1, 2021 · 1 comment

Comments

@kushwahashiv
Copy link

kushwahashiv commented Mar 1, 2021

Hi All

I'm facing hyper request timeout implement/migration issue. earlier implementation is similar to below
#1097

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

@davidbarsky
Copy link
Contributor

davidbarsky commented Mar 1, 2021

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(())
}

@hyperium hyperium locked and limited conversation to collaborators Mar 1, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants