diff --git a/src/main.rs b/src/main.rs index 1029cac..a88447f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,9 @@ use color_eyre::Report; use reqwest::Client; +use tokio::time::sleep; use tracing::info; use tracing_subscriber::EnvFilter; +use std::time::Duration; pub const URL_1: &str = "https://fasterthanli.me/articles/whats-in-the-box"; @@ -12,12 +14,14 @@ async fn main() -> Result<(), Report> { setup()?; let client = Client::new(); + let leaked_client = Box::leak(Box::new(client)); - let fut1 = fetch_thing(&client, URL_1); - let fut2 = fetch_thing(&client, URL_2); + let fut1 = fetch_thing(leaked_client, URL_1); + tokio::spawn(fut1); + let fut2 = fetch_thing(leaked_client, URL_2); + tokio::spawn(fut2); - fut1.await?; - fut2.await?; + tokio::time::sleep(Duration::from_secs(1)).await; Ok(()) } @@ -45,10 +49,10 @@ fn setup() -> Result<(), Report> { // } // use std::future::Future; -fn fetch_thing<'a> ( - client: &'a Client, - url: &'a str, -) -> impl Future> + 'a { +fn fetch_thing ( + client: &'static Client, + url: &'static str, +) -> impl Future> + 'static { async move { let res = client.get(url).send().await?.error_for_status()?; info!(%url, content_type = ?res.headers().get("content-type"), "Got a response!");