How can I put the current thread to sleep?
You can sleep Thread in Rust usingDuration
and sleep
and you call from_millis
function which takes number of milliseconds.use std::time::Duration;
use std::thread::sleep;
fn main() {
sleep(Duration::from_millis(2));
}
AnotherExample of Sleep function
Below example will sleep for 5 seconds as 5000 milliseconds = 5 seconds.use std::time::Duration;
use std::thread::sleep;
fn main() {
sleep(Duration::from_millis(5000));
}