diff options
| author | Brian Anderson <banderson@mozilla.com> | 2014-07-14 19:30:05 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2014-08-13 11:31:47 -0700 |
| commit | 657b679b158894556628f096a28aab364b605446 (patch) | |
| tree | 22fde9a2df8b169869838c90661fec4a88089a52 | |
| parent | 5778ed4c926da6069ab899c8d4694527ed89190c (diff) | |
| download | rust-657b679b158894556628f096a28aab364b605446.tar.gz rust-657b679b158894556628f096a28aab364b605446.zip | |
std: Rename sleep, periodic, and oneshot timers to sleep_ms, etc.
Rename io::timer::sleep, Timer::sleep, Timer::oneshot, Timer::periodic, to sleep_ms, oneshot_ms, periodic_ms. These functions all take an integer and interpret it as milliseconds. Replacement functions will be added that take Duration. [breaking-change]
| -rw-r--r-- | src/libstd/io/process.rs | 2 | ||||
| -rw-r--r-- | src/libstd/io/signal.rs | 6 | ||||
| -rw-r--r-- | src/libstd/io/timer.rs | 102 | ||||
| -rw-r--r-- | src/libstd/lib.rs | 2 | ||||
| -rw-r--r-- | src/libstd/task.rs | 2 | ||||
| -rw-r--r-- | src/libstd/time.rs (renamed from src/libstd/duration.rs) | 1 |
6 files changed, 58 insertions, 57 deletions
diff --git a/src/libstd/io/process.rs b/src/libstd/io/process.rs index c82b4831341..41a621f6edf 100644 --- a/src/libstd/io/process.rs +++ b/src/libstd/io/process.rs @@ -976,7 +976,7 @@ mod tests { assert!(!p.wait().unwrap().success()); return } - timer::sleep(100); + timer::sleep_ms(100); } fail!("never saw the child go away"); }) diff --git a/src/libstd/io/signal.rs b/src/libstd/io/signal.rs index c126866e715..4ea91131f17 100644 --- a/src/libstd/io/signal.rs +++ b/src/libstd/io/signal.rs @@ -179,7 +179,7 @@ mod test_unix { let mut signal = Listener::new(); signal.register(Interrupt).unwrap(); sigint(); - timer::sleep(10); + timer::sleep_ms(10); match signal.rx.recv() { Interrupt => (), s => fail!("Expected Interrupt, got {:?}", s), @@ -193,7 +193,7 @@ mod test_unix { s1.register(Interrupt).unwrap(); s2.register(Interrupt).unwrap(); sigint(); - timer::sleep(10); + timer::sleep_ms(10); match s1.rx.recv() { Interrupt => (), s => fail!("Expected Interrupt, got {:?}", s), @@ -212,7 +212,7 @@ mod test_unix { s2.register(Interrupt).unwrap(); s2.unregister(Interrupt); sigint(); - timer::sleep(10); + timer::sleep_ms(10); assert_eq!(s2.rx.try_recv(), Err(Empty)); } } diff --git a/src/libstd/io/timer.rs b/src/libstd/io/timer.rs index 1c9e428dcad..906a2800201 100644 --- a/src/libstd/io/timer.rs +++ b/src/libstd/io/timer.rs @@ -70,11 +70,11 @@ pub struct Timer { struct TimerCallback { tx: Sender<()> } /// Sleep the current task for `msecs` milliseconds. -pub fn sleep(msecs: u64) { +pub fn sleep_ms(msecs: u64) { let timer = Timer::new(); let mut timer = timer.ok().expect("timer::sleep: could not create a Timer"); - timer.sleep(msecs) + timer.sleep_ms(msecs) } impl Timer { @@ -91,7 +91,7 @@ impl Timer { /// /// Note that this function will cause any other receivers for this timer to /// be invalidated (the other end will be closed). - pub fn sleep(&mut self, msecs: u64) { + pub fn sleep_ms(&mut self, msecs: u64) { self.obj.sleep(msecs); } @@ -129,7 +129,7 @@ impl Timer { /// // The timer object was destroyed, so this will always fail: /// // five_ms.recv() /// ``` - pub fn oneshot(&mut self, msecs: u64) -> Receiver<()> { + pub fn oneshot_ms(&mut self, msecs: u64) -> Receiver<()> { let (tx, rx) = channel(); self.obj.oneshot(msecs, box TimerCallback { tx: tx }); return rx @@ -177,7 +177,7 @@ impl Timer { /// // The timer object was destroyed, so this will always fail: /// // five_ms.recv() /// ``` - pub fn periodic(&mut self, msecs: u64) -> Receiver<()> { + pub fn periodic_ms(&mut self, msecs: u64) -> Receiver<()> { let (tx, rx) = channel(); self.obj.period(msecs, box TimerCallback { tx: tx }); return rx @@ -192,101 +192,101 @@ impl Callback for TimerCallback { #[cfg(test)] mod test { - iotest!(fn test_io_timer_sleep_simple() { + iotest!(fn test_io_timer_sleep_ms_simple() { let mut timer = Timer::new().unwrap(); - timer.sleep(1); + timer.sleep_ms(1); }) - iotest!(fn test_io_timer_sleep_oneshot() { + iotest!(fn test_io_timer_sleep_oneshot_ms() { let mut timer = Timer::new().unwrap(); - timer.oneshot(1).recv(); + timer.oneshot_ms(1).recv(); }) - iotest!(fn test_io_timer_sleep_oneshot_forget() { + iotest!(fn test_io_timer_sleep_oneshot_ms_forget() { let mut timer = Timer::new().unwrap(); - timer.oneshot(100000000000); + timer.oneshot_ms(100000000000); }) - iotest!(fn oneshot_twice() { + iotest!(fn oneshot_ms_twice() { let mut timer = Timer::new().unwrap(); - let rx1 = timer.oneshot(10000); - let rx = timer.oneshot(1); + let rx1 = timer.oneshot_ms(10000); + let rx = timer.oneshot_ms(1); rx.recv(); assert_eq!(rx1.recv_opt(), Err(())); }) - iotest!(fn test_io_timer_oneshot_then_sleep() { + iotest!(fn test_io_timer_oneshot_ms_then_sleep() { let mut timer = Timer::new().unwrap(); - let rx = timer.oneshot(100000000000); - timer.sleep(1); // this should invalidate rx + let rx = timer.oneshot_ms(100000000000); + timer.sleep_ms(1); // this should invalidate rx assert_eq!(rx.recv_opt(), Err(())); }) - iotest!(fn test_io_timer_sleep_periodic() { + iotest!(fn test_io_timer_sleep_periodic_ms() { let mut timer = Timer::new().unwrap(); - let rx = timer.periodic(1); + let rx = timer.periodic_ms(1); rx.recv(); rx.recv(); rx.recv(); }) - iotest!(fn test_io_timer_sleep_periodic_forget() { + iotest!(fn test_io_timer_sleep_periodic_ms_forget() { let mut timer = Timer::new().unwrap(); - timer.periodic(100000000000); + timer.periodic_ms(100000000000); }) - iotest!(fn test_io_timer_sleep_standalone() { - sleep(1) + iotest!(fn test_io_timer_sleep_ms_standalone() { + sleep_ms(1) }) - iotest!(fn oneshot() { + iotest!(fn oneshot_ms() { let mut timer = Timer::new().unwrap(); - let rx = timer.oneshot(1); + let rx = timer.oneshot_ms(1); rx.recv(); assert!(rx.recv_opt().is_err()); - let rx = timer.oneshot(1); + let rx = timer.oneshot_ms(1); rx.recv(); assert!(rx.recv_opt().is_err()); }) iotest!(fn override() { let mut timer = Timer::new().unwrap(); - let orx = timer.oneshot(100); - let prx = timer.periodic(100); - timer.sleep(1); + let orx = timer.oneshot_ms(100); + let prx = timer.periodic_ms(100); + timer.sleep_ms(1); assert_eq!(orx.recv_opt(), Err(())); assert_eq!(prx.recv_opt(), Err(())); - timer.oneshot(1).recv(); + timer.oneshot_ms(1).recv(); }) - iotest!(fn period() { + iotest!(fn period_ms() { let mut timer = Timer::new().unwrap(); - let rx = timer.periodic(1); + let rx = timer.periodic_ms(1); rx.recv(); rx.recv(); - let rx2 = timer.periodic(1); + let rx2 = timer.periodic_ms(1); rx2.recv(); rx2.recv(); }) - iotest!(fn sleep() { + iotest!(fn sleep_ms() { let mut timer = Timer::new().unwrap(); - timer.sleep(1); - timer.sleep(1); + timer.sleep_ms(1); + timer.sleep_ms(1); }) - iotest!(fn oneshot_fail() { + iotest!(fn oneshot_ms_fail() { let mut timer = Timer::new().unwrap(); - let _rx = timer.oneshot(1); + let _rx = timer.oneshot_ms(1); fail!(); } #[should_fail]) - iotest!(fn period_fail() { + iotest!(fn period_ms_fail() { let mut timer = Timer::new().unwrap(); - let _rx = timer.periodic(1); + let _rx = timer.periodic_ms(1); fail!(); } #[should_fail]) @@ -298,7 +298,7 @@ mod test { iotest!(fn closing_channel_during_drop_doesnt_kill_everything() { // see issue #10375 let mut timer = Timer::new().unwrap(); - let timer_rx = timer.periodic(1000); + let timer_rx = timer.periodic_ms(1000); spawn(proc() { let _ = timer_rx.recv_opt(); @@ -311,31 +311,31 @@ mod test { iotest!(fn reset_doesnt_switch_tasks() { // similar test to the one above. let mut timer = Timer::new().unwrap(); - let timer_rx = timer.periodic(1000); + let timer_rx = timer.periodic_ms(1000); spawn(proc() { let _ = timer_rx.recv_opt(); }); - timer.oneshot(1); + timer.oneshot_ms(1); }) iotest!(fn reset_doesnt_switch_tasks2() { // similar test to the one above. let mut timer = Timer::new().unwrap(); - let timer_rx = timer.periodic(1000); + let timer_rx = timer.periodic_ms(1000); spawn(proc() { let _ = timer_rx.recv_opt(); }); - timer.sleep(1); + timer.sleep_ms(1); }) iotest!(fn sender_goes_away_oneshot() { let rx = { let mut timer = Timer::new().unwrap(); - timer.oneshot(1000) + timer.oneshot_ms(1000) }; assert_eq!(rx.recv_opt(), Err(())); }) @@ -343,26 +343,26 @@ mod test { iotest!(fn sender_goes_away_period() { let rx = { let mut timer = Timer::new().unwrap(); - timer.periodic(1000) + timer.periodic_ms(1000) }; assert_eq!(rx.recv_opt(), Err(())); }) iotest!(fn receiver_goes_away_oneshot() { let mut timer1 = Timer::new().unwrap(); - timer1.oneshot(1); + timer1.oneshot_ms(1); let mut timer2 = Timer::new().unwrap(); // while sleeping, the previous timer should fire and not have its // callback do something terrible. - timer2.sleep(2); + timer2.sleep_ms(2); }) iotest!(fn receiver_goes_away_period() { let mut timer1 = Timer::new().unwrap(); - timer1.periodic(1); + timer1.periodic_ms(1); let mut timer2 = Timer::new().unwrap(); // while sleeping, the previous timer should fire and not have its // callback do something terrible. - timer2.sleep(2); + timer2.sleep_ms(2); }) } diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index f2db4944de4..103cd574e73 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -233,7 +233,7 @@ pub mod ascii; #[cfg(not(test))] pub mod gc; -pub mod duration; +pub mod time; /* Common traits */ diff --git a/src/libstd/task.rs b/src/libstd/task.rs index 19ad81a0483..96036b54e36 100644 --- a/src/libstd/task.rs +++ b/src/libstd/task.rs @@ -669,5 +669,5 @@ fn task_abort_no_kill_runtime() { let tb = TaskBuilder::new(); let rx = tb.try_future(proc() {}); mem::drop(rx); - timer::sleep(1000); + timer::sleep_ms(1000); } diff --git a/src/libstd/duration.rs b/src/libstd/time.rs index 7bc07d7acb6..d9a2f4b3cab 100644 --- a/src/libstd/duration.rs +++ b/src/libstd/time.rs @@ -342,6 +342,7 @@ fn div_rem_64(this: i64, other: i64) -> (i64, i64) { #[cfg(test)] mod tests { + use option::Some; use super::{Duration, MIN_DAYS, MAX_DAYS}; use i32; use num::{CheckedAdd, CheckedSub, Zero}; |
