Last active
December 17, 2022 18:39
-
-
Save kenyipp/f0c67a24d815337271a5523e5ef9d069 to your computer and use it in GitHub Desktop.
Future that sleep for certain milliseconds and return a string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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