Skip to content

Commit

Permalink
examples: Replace deprecated sleep_ms() with sleep()
Browse files Browse the repository at this point in the history
std::thread::sleep_ms() is deprecated since Rust 1.6.0
  • Loading branch information
l0kod committed Oct 16, 2016
1 parent e85ea62 commit ebd6dae
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ in a separate thread) or for a signal to be delivered:
extern crate chan;
extern crate chan_signal;

use std::thread;
use std::time::Duration;

use chan_signal::Signal;

fn main() {
Expand All @@ -49,7 +52,7 @@ fn main() {
// When our work is complete, send a sentinel value on `sdone`.
let (sdone, rdone) = chan::sync(0);
// Run work.
::std::thread::spawn(move || run(sdone));
thread::spawn(move || run(sdone));

// Wait for a signal or for work to be done.
chan_select! {
Expand All @@ -66,7 +69,7 @@ fn run(_sdone: chan::Sender<()>) {
println!("Running work for 5 seconds.");
println!("Can you send a signal quickly enough?");
// Do some work.
::std::thread::sleep_ms(5000);
thread::sleep(Duration::from_secs(5));

// _sdone gets dropped which closes the channel and causes `rdone`
// to unblock.
Expand Down
7 changes: 5 additions & 2 deletions examples/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
extern crate chan;
extern crate chan_signal;

use std::thread;
use std::time::Duration;

use chan_signal::Signal;

fn main() {
Expand All @@ -10,7 +13,7 @@ fn main() {
// When our work is complete, send a sentinel value on `sdone`.
let (sdone, rdone) = chan::sync(0);
// Run work.
::std::thread::spawn(move || run(sdone));
thread::spawn(move || run(sdone));

// Wait for a signal or for work to be done.
chan_select! {
Expand All @@ -27,5 +30,5 @@ fn run(_sdone: chan::Sender<()>) {
println!("Running work for 5 seconds.");
println!("Can you send a signal quickly enough?");
// Do some work.
::std::thread::sleep_ms(5000);
thread::sleep(Duration::from_secs(5));
}
4 changes: 2 additions & 2 deletions examples/sleep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
extern crate chan_signal;

use std::thread;
use std::time::Duration;

use chan_signal::{Signal, notify};

fn main() {
let signal = notify(&[Signal::INT]);
println!("Send a TERM signal my way!");
thread::spawn(move || thread::sleep_ms(10000));
// thread::sleep_ms(5000);
thread::spawn(move || thread::sleep(Duration::from_secs(10)));
// block until we get a signal
assert_eq!(signal.recv(), Some(Signal::INT));
println!("Thanks :]");
Expand Down
5 changes: 3 additions & 2 deletions examples/test_sleep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ extern crate chan;
extern crate chan_signal;

use std::thread;
use std::time::Duration;

use chan_signal::{Signal, kill_this};

fn main() {
let (s, r) = chan::sync(1);
chan_signal::notify_on(&s, Signal::HUP);
thread::spawn(move || thread::sleep_ms(10000));
thread::sleep_ms(500);
thread::spawn(move || thread::sleep(Duration::from_secs(10)));
thread::sleep(Duration::from_millis(500));
kill_this(Signal::HUP);
assert_eq!(r.recv(), Some(Signal::HUP));
}

0 comments on commit ebd6dae

Please sign in to comment.