Fix various fallout from timer changes

This commit is contained in:
Brian Anderson 2014-08-01 18:05:26 -07:00
parent 80d32438d6
commit a391934ba8
9 changed files with 35 additions and 19 deletions

View File

@ -1029,6 +1029,7 @@ mod test {
use std::rt::task::TaskOpts;
use std::rt::task::Task;
use std::rt::local::Local;
use std::time::Duration;
use {TaskState, PoolConfig, SchedPool};
use basic;
@ -1291,7 +1292,7 @@ mod test {
// doesn't exit before emptying the work queue
pool.spawn(TaskOpts::new(), proc() {
spawn(proc() {
timer::sleep(10);
timer::sleep(Duration::milliseconds(10));
});
});

View File

@ -171,13 +171,14 @@ impl TcpStream {
/// # #![allow(unused_must_use)]
/// use std::io::timer;
/// use std::io::TcpStream;
/// use std::time::Duration;
///
/// let mut stream = TcpStream::connect("127.0.0.1", 34254).unwrap();
/// let stream2 = stream.clone();
///
/// spawn(proc() {
/// // close this stream after one second
/// timer::sleep(1000);
/// timer::sleep(Duration::seconds(1));
/// let mut stream = stream2;
/// stream.close_read();
/// });

View File

@ -38,15 +38,16 @@ use rt::rtio::{IoFactory, LocalIo, RtioTimer, Callback};
/// # fn main() {}
/// # fn foo() {
/// use std::io::Timer;
/// use std::time::Duration;
///
/// let mut timer = Timer::new().unwrap();
/// timer.sleep(10); // block the task for awhile
/// timer.sleep(Duration::milliseconds(10)); // block the task for awhile
///
/// let timeout = timer.oneshot(10);
/// let timeout = timer.oneshot(Duration::milliseconds(10));
/// // do some work
/// timeout.recv(); // wait for the timeout to expire
///
/// let periodic = timer.periodic(10);
/// let periodic = timer.periodic(Duration::milliseconds(10));
/// loop {
/// periodic.recv();
/// // this loop is only executed once every 10ms
@ -61,9 +62,10 @@ use rt::rtio::{IoFactory, LocalIo, RtioTimer, Callback};
/// # fn main() {}
/// # fn foo() {
/// use std::io::timer;
/// use std::time::Duration;
///
/// // Put this task to sleep for 5 seconds
/// timer::sleep(5000);
/// timer::sleep(Duration::seconds(5));
/// # }
/// ```
pub struct Timer {
@ -123,9 +125,10 @@ impl Timer {
///
/// ```rust
/// use std::io::Timer;
/// use std::time::Duration;
///
/// let mut timer = Timer::new().unwrap();
/// let ten_milliseconds = timer.oneshot(10);
/// let ten_milliseconds = timer.oneshot(Duration::milliseconds(10));
///
/// for _ in range(0u, 100) { /* do work */ }
///
@ -135,9 +138,10 @@ impl Timer {
///
/// ```rust
/// use std::io::Timer;
/// use std::time::Duration;
///
/// // Incorrect, method chaining-style:
/// let mut five_ms = Timer::new().unwrap().oneshot(5);
/// let mut five_ms = Timer::new().unwrap().oneshot(Duration::milliseconds(5));
/// // The timer object was destroyed, so this will always fail:
/// // five_ms.recv()
/// ```
@ -173,9 +177,10 @@ impl Timer {
///
/// ```rust
/// use std::io::Timer;
/// use std::time::Duration;
///
/// let mut timer = Timer::new().unwrap();
/// let ten_milliseconds = timer.periodic(10);
/// let ten_milliseconds = timer.periodic(Duration::milliseconds(10));
///
/// for _ in range(0u, 100) { /* do work */ }
///
@ -191,9 +196,10 @@ impl Timer {
///
/// ```rust
/// use std::io::Timer;
/// use std::time::Duration;
///
/// // Incorrect, method chaining-style.
/// let mut five_ms = Timer::new().unwrap().periodic(5);
/// let mut five_ms = Timer::new().unwrap().periodic(Duration::milliseconds(5));
/// // The timer object was destroyed, so this will always fail:
/// // five_ms.recv()
/// ```

View File

@ -128,10 +128,11 @@
//!
//! ```no_run
//! use std::io::timer::Timer;
//! use std::time::Duration;
//!
//! let (tx, rx) = channel::<int>();
//! let mut timer = Timer::new().unwrap();
//! let timeout = timer.oneshot(10000);
//! let timeout = timer.oneshot(Duration::seconds(10));
//!
//! loop {
//! select! {
@ -150,12 +151,13 @@
//!
//! ```no_run
//! use std::io::timer::Timer;
//! use std::time::Duration;
//!
//! let (tx, rx) = channel::<int>();
//! let mut timer = Timer::new().unwrap();
//!
//! loop {
//! let timeout = timer.oneshot(5000);
//! let timeout = timer.oneshot(Duration::seconds(5));
//!
//! select! {
//! val = rx.recv() => println!("Received {}", val),

View File

@ -25,6 +25,7 @@ extern crate green;
extern crate rustuv;
use std::io::{Process, Command};
use std::time::Duration;
macro_rules! succeed( ($e:expr) => (
match $e { Ok(..) => {}, Err(e) => fail!("failure: {}", e) }
@ -115,7 +116,7 @@ pub fn test_destroy_actually_kills(force: bool) {
// Don't let this test time out, this should be quick
let (tx, rx1) = channel();
let mut t = timer::Timer::new().unwrap();
let rx2 = t.oneshot(1000);
let rx2 = t.oneshot(Duration::milliseconds(1000));
spawn(proc() {
select! {
() = rx2.recv() => unsafe { libc::exit(1) },

View File

@ -13,6 +13,8 @@ extern crate native;
extern crate green;
extern crate rustuv;
use std::time::Duration;
#[start]
fn start(argc: int, argv: *const *const u8) -> int {
green::start(argc, argv, rustuv::event_loop, main)
@ -24,6 +26,6 @@ fn main() {
fn customtask() {
let mut timer = std::io::timer::Timer::new().unwrap();
let periodic = timer.periodic(10);
let periodic = timer.periodic(Duration::milliseconds(10));
periodic.recv();
}

View File

@ -12,6 +12,7 @@
extern crate native;
use std::io::timer;
use std::time::Duration;
#[start]
fn start(argc: int, argv: *const *const u8) -> int {
@ -19,5 +20,5 @@ fn start(argc: int, argv: *const *const u8) -> int {
}
fn main() {
timer::sleep(250);
timer::sleep(Duration::milliseconds(250));
}

View File

@ -10,12 +10,13 @@
use std::comm;
use std::io::timer::Timer;
use std::time::Duration;
pub fn main() {
let (tx, rx) = channel();
spawn(proc (){
let mut timer = Timer::new().unwrap();
timer.sleep(10);
timer.sleep(Duration::milliseconds(10));
tx.send(());
});
loop {

View File

@ -38,6 +38,7 @@ macro_rules! iotest (
use std::io::net::tcp::*;
use std::io::test::*;
use std::io;
use std::time::Duration;
fn f() $b
@ -72,7 +73,7 @@ iotest!(fn eventual_timeout() {
let mut v = Vec::new();
for _ in range(0u, 10000) {
match TcpStream::connect_timeout(addr, 100) {
match TcpStream::connect_timeout(addr, Duration::milliseconds(100)) {
Ok(e) => v.push(e),
Err(ref e) if e.kind == io::TimedOut => return,
Err(e) => fail!("other error: {}", e),
@ -87,11 +88,11 @@ iotest!(fn timeout_success() {
let port = addr.port;
let _l = TcpListener::bind(host.as_slice(), port).unwrap().listen();
assert!(TcpStream::connect_timeout(addr, 1000).is_ok());
assert!(TcpStream::connect_timeout(addr, Duration::milliseconds(1000)).is_ok());
})
iotest!(fn timeout_error() {
let addr = next_test_ip4();
assert!(TcpStream::connect_timeout(addr, 1000).is_err());
assert!(TcpStream::connect_timeout(addr, Duration::milliseconds(1000)).is_err());
})