Skip to content

Instantly share code, notes, and snippets.

@kenyipp
Last active December 17, 2022 18:39
Show Gist options
  • Save kenyipp/f0c67a24d815337271a5523e5ef9d069 to your computer and use it in GitHub Desktop.
Save kenyipp/f0c67a24d815337271a5523e5ef9d069 to your computer and use it in GitHub Desktop.
Future that sleep for certain milliseconds and return a string
use std::thread::sleep;
use std::time::Duration;
use anyhow::Result;
#[tokio::main]
async fn main() -> Result<()> {
sleep_and_run_and_return_string(1000).await;
println!("I have been waiting for 1 seconds");
Ok(())
}
async fn sleep_and_run_and_return_string(millisecond: u64) -> String {
sleep(Duration::from_millis(millisecond));
String::from("Hello guys!")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment