Skip to content

How to implement hyper request timeout  #2448

Closed

Description

@kushwahashiv

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

Activity

  1. davidbarsky commented on Mar 1, 2021

    @davidbarsky
    Contributor

    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. locked and limited conversation to collaborators on Mar 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions