Logo

Programming-Idioms

History of Idiom 45 > diff from v41 to v42

Edit summary for version 42 by natejms:
[Rust] Previous method was depricated

Version 41

2017-03-07, 10:31:16

Version 42

2017-05-16, 19:12:36

Idiom #45 Pause execution for 5 seconds

Sleep for 5 seconds in current thread, before proceeding with next instructions.

Illustration

Idiom #45 Pause execution for 5 seconds

Sleep for 5 seconds in current thread, before proceeding with next instructions.

Illustration
Imports
use std::thread::sleep_ms;
Imports
use std::{thread, time};
Code
sleep_ms(5000);
Code
thread::sleep(time::Duration::from_millis(5000));
Doc URL
https://doc.rust-lang.org/std/thread/fn.sleep.html
Demo URL
https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3A%7Bthread%2C%20time%7D%3B%0A%0Alet%20ten_millis%20%3D%20time%3A%3ADuration%3A%3Afrom_millis(10)%3B%0Alet%20now%20%3D%20time%3A%3AInstant%3A%3Anow()%3B%0A%0Athread%3A%3Asleep(ten_mill