Fix various fallout from timer changes
This commit is contained in:
parent
80d32438d6
commit
a391934ba8
@ -1029,6 +1029,7 @@ mod test {
|
|||||||
use std::rt::task::TaskOpts;
|
use std::rt::task::TaskOpts;
|
||||||
use std::rt::task::Task;
|
use std::rt::task::Task;
|
||||||
use std::rt::local::Local;
|
use std::rt::local::Local;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use {TaskState, PoolConfig, SchedPool};
|
use {TaskState, PoolConfig, SchedPool};
|
||||||
use basic;
|
use basic;
|
||||||
@ -1291,7 +1292,7 @@ mod test {
|
|||||||
// doesn't exit before emptying the work queue
|
// doesn't exit before emptying the work queue
|
||||||
pool.spawn(TaskOpts::new(), proc() {
|
pool.spawn(TaskOpts::new(), proc() {
|
||||||
spawn(proc() {
|
spawn(proc() {
|
||||||
timer::sleep(10);
|
timer::sleep(Duration::milliseconds(10));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -171,13 +171,14 @@ impl TcpStream {
|
|||||||
/// # #![allow(unused_must_use)]
|
/// # #![allow(unused_must_use)]
|
||||||
/// use std::io::timer;
|
/// use std::io::timer;
|
||||||
/// use std::io::TcpStream;
|
/// use std::io::TcpStream;
|
||||||
|
/// use std::time::Duration;
|
||||||
///
|
///
|
||||||
/// let mut stream = TcpStream::connect("127.0.0.1", 34254).unwrap();
|
/// let mut stream = TcpStream::connect("127.0.0.1", 34254).unwrap();
|
||||||
/// let stream2 = stream.clone();
|
/// let stream2 = stream.clone();
|
||||||
///
|
///
|
||||||
/// spawn(proc() {
|
/// spawn(proc() {
|
||||||
/// // close this stream after one second
|
/// // close this stream after one second
|
||||||
/// timer::sleep(1000);
|
/// timer::sleep(Duration::seconds(1));
|
||||||
/// let mut stream = stream2;
|
/// let mut stream = stream2;
|
||||||
/// stream.close_read();
|
/// stream.close_read();
|
||||||
/// });
|
/// });
|
||||||
|
@ -38,15 +38,16 @@ use rt::rtio::{IoFactory, LocalIo, RtioTimer, Callback};
|
|||||||
/// # fn main() {}
|
/// # fn main() {}
|
||||||
/// # fn foo() {
|
/// # fn foo() {
|
||||||
/// use std::io::Timer;
|
/// use std::io::Timer;
|
||||||
|
/// use std::time::Duration;
|
||||||
///
|
///
|
||||||
/// let mut timer = Timer::new().unwrap();
|
/// 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
|
/// // do some work
|
||||||
/// timeout.recv(); // wait for the timeout to expire
|
/// timeout.recv(); // wait for the timeout to expire
|
||||||
///
|
///
|
||||||
/// let periodic = timer.periodic(10);
|
/// let periodic = timer.periodic(Duration::milliseconds(10));
|
||||||
/// loop {
|
/// loop {
|
||||||
/// periodic.recv();
|
/// periodic.recv();
|
||||||
/// // this loop is only executed once every 10ms
|
/// // this loop is only executed once every 10ms
|
||||||
@ -61,9 +62,10 @@ use rt::rtio::{IoFactory, LocalIo, RtioTimer, Callback};
|
|||||||
/// # fn main() {}
|
/// # fn main() {}
|
||||||
/// # fn foo() {
|
/// # fn foo() {
|
||||||
/// use std::io::timer;
|
/// use std::io::timer;
|
||||||
|
/// use std::time::Duration;
|
||||||
///
|
///
|
||||||
/// // Put this task to sleep for 5 seconds
|
/// // Put this task to sleep for 5 seconds
|
||||||
/// timer::sleep(5000);
|
/// timer::sleep(Duration::seconds(5));
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
pub struct Timer {
|
pub struct Timer {
|
||||||
@ -123,9 +125,10 @@ impl Timer {
|
|||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use std::io::Timer;
|
/// use std::io::Timer;
|
||||||
|
/// use std::time::Duration;
|
||||||
///
|
///
|
||||||
/// let mut timer = Timer::new().unwrap();
|
/// 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 */ }
|
/// for _ in range(0u, 100) { /* do work */ }
|
||||||
///
|
///
|
||||||
@ -135,9 +138,10 @@ impl Timer {
|
|||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use std::io::Timer;
|
/// use std::io::Timer;
|
||||||
|
/// use std::time::Duration;
|
||||||
///
|
///
|
||||||
/// // Incorrect, method chaining-style:
|
/// // 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:
|
/// // The timer object was destroyed, so this will always fail:
|
||||||
/// // five_ms.recv()
|
/// // five_ms.recv()
|
||||||
/// ```
|
/// ```
|
||||||
@ -173,9 +177,10 @@ impl Timer {
|
|||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use std::io::Timer;
|
/// use std::io::Timer;
|
||||||
|
/// use std::time::Duration;
|
||||||
///
|
///
|
||||||
/// let mut timer = Timer::new().unwrap();
|
/// 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 */ }
|
/// for _ in range(0u, 100) { /* do work */ }
|
||||||
///
|
///
|
||||||
@ -191,9 +196,10 @@ impl Timer {
|
|||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use std::io::Timer;
|
/// use std::io::Timer;
|
||||||
|
/// use std::time::Duration;
|
||||||
///
|
///
|
||||||
/// // Incorrect, method chaining-style.
|
/// // 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:
|
/// // The timer object was destroyed, so this will always fail:
|
||||||
/// // five_ms.recv()
|
/// // five_ms.recv()
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -128,10 +128,11 @@
|
|||||||
//!
|
//!
|
||||||
//! ```no_run
|
//! ```no_run
|
||||||
//! use std::io::timer::Timer;
|
//! use std::io::timer::Timer;
|
||||||
|
//! use std::time::Duration;
|
||||||
//!
|
//!
|
||||||
//! let (tx, rx) = channel::<int>();
|
//! let (tx, rx) = channel::<int>();
|
||||||
//! let mut timer = Timer::new().unwrap();
|
//! let mut timer = Timer::new().unwrap();
|
||||||
//! let timeout = timer.oneshot(10000);
|
//! let timeout = timer.oneshot(Duration::seconds(10));
|
||||||
//!
|
//!
|
||||||
//! loop {
|
//! loop {
|
||||||
//! select! {
|
//! select! {
|
||||||
@ -150,12 +151,13 @@
|
|||||||
//!
|
//!
|
||||||
//! ```no_run
|
//! ```no_run
|
||||||
//! use std::io::timer::Timer;
|
//! use std::io::timer::Timer;
|
||||||
|
//! use std::time::Duration;
|
||||||
//!
|
//!
|
||||||
//! let (tx, rx) = channel::<int>();
|
//! let (tx, rx) = channel::<int>();
|
||||||
//! let mut timer = Timer::new().unwrap();
|
//! let mut timer = Timer::new().unwrap();
|
||||||
//!
|
//!
|
||||||
//! loop {
|
//! loop {
|
||||||
//! let timeout = timer.oneshot(5000);
|
//! let timeout = timer.oneshot(Duration::seconds(5));
|
||||||
//!
|
//!
|
||||||
//! select! {
|
//! select! {
|
||||||
//! val = rx.recv() => println!("Received {}", val),
|
//! val = rx.recv() => println!("Received {}", val),
|
||||||
|
@ -25,6 +25,7 @@ extern crate green;
|
|||||||
extern crate rustuv;
|
extern crate rustuv;
|
||||||
|
|
||||||
use std::io::{Process, Command};
|
use std::io::{Process, Command};
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
macro_rules! succeed( ($e:expr) => (
|
macro_rules! succeed( ($e:expr) => (
|
||||||
match $e { Ok(..) => {}, Err(e) => fail!("failure: {}", e) }
|
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
|
// Don't let this test time out, this should be quick
|
||||||
let (tx, rx1) = channel();
|
let (tx, rx1) = channel();
|
||||||
let mut t = timer::Timer::new().unwrap();
|
let mut t = timer::Timer::new().unwrap();
|
||||||
let rx2 = t.oneshot(1000);
|
let rx2 = t.oneshot(Duration::milliseconds(1000));
|
||||||
spawn(proc() {
|
spawn(proc() {
|
||||||
select! {
|
select! {
|
||||||
() = rx2.recv() => unsafe { libc::exit(1) },
|
() = rx2.recv() => unsafe { libc::exit(1) },
|
||||||
|
@ -13,6 +13,8 @@ extern crate native;
|
|||||||
extern crate green;
|
extern crate green;
|
||||||
extern crate rustuv;
|
extern crate rustuv;
|
||||||
|
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
#[start]
|
#[start]
|
||||||
fn start(argc: int, argv: *const *const u8) -> int {
|
fn start(argc: int, argv: *const *const u8) -> int {
|
||||||
green::start(argc, argv, rustuv::event_loop, main)
|
green::start(argc, argv, rustuv::event_loop, main)
|
||||||
@ -24,6 +26,6 @@ fn main() {
|
|||||||
|
|
||||||
fn customtask() {
|
fn customtask() {
|
||||||
let mut timer = std::io::timer::Timer::new().unwrap();
|
let mut timer = std::io::timer::Timer::new().unwrap();
|
||||||
let periodic = timer.periodic(10);
|
let periodic = timer.periodic(Duration::milliseconds(10));
|
||||||
periodic.recv();
|
periodic.recv();
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
extern crate native;
|
extern crate native;
|
||||||
|
|
||||||
use std::io::timer;
|
use std::io::timer;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
#[start]
|
#[start]
|
||||||
fn start(argc: int, argv: *const *const u8) -> int {
|
fn start(argc: int, argv: *const *const u8) -> int {
|
||||||
@ -19,5 +20,5 @@ fn start(argc: int, argv: *const *const u8) -> int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
timer::sleep(250);
|
timer::sleep(Duration::milliseconds(250));
|
||||||
}
|
}
|
||||||
|
@ -10,12 +10,13 @@
|
|||||||
|
|
||||||
use std::comm;
|
use std::comm;
|
||||||
use std::io::timer::Timer;
|
use std::io::timer::Timer;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let (tx, rx) = channel();
|
let (tx, rx) = channel();
|
||||||
spawn(proc (){
|
spawn(proc (){
|
||||||
let mut timer = Timer::new().unwrap();
|
let mut timer = Timer::new().unwrap();
|
||||||
timer.sleep(10);
|
timer.sleep(Duration::milliseconds(10));
|
||||||
tx.send(());
|
tx.send(());
|
||||||
});
|
});
|
||||||
loop {
|
loop {
|
||||||
|
@ -38,6 +38,7 @@ macro_rules! iotest (
|
|||||||
use std::io::net::tcp::*;
|
use std::io::net::tcp::*;
|
||||||
use std::io::test::*;
|
use std::io::test::*;
|
||||||
use std::io;
|
use std::io;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
fn f() $b
|
fn f() $b
|
||||||
|
|
||||||
@ -72,7 +73,7 @@ iotest!(fn eventual_timeout() {
|
|||||||
|
|
||||||
let mut v = Vec::new();
|
let mut v = Vec::new();
|
||||||
for _ in range(0u, 10000) {
|
for _ in range(0u, 10000) {
|
||||||
match TcpStream::connect_timeout(addr, 100) {
|
match TcpStream::connect_timeout(addr, Duration::milliseconds(100)) {
|
||||||
Ok(e) => v.push(e),
|
Ok(e) => v.push(e),
|
||||||
Err(ref e) if e.kind == io::TimedOut => return,
|
Err(ref e) if e.kind == io::TimedOut => return,
|
||||||
Err(e) => fail!("other error: {}", e),
|
Err(e) => fail!("other error: {}", e),
|
||||||
@ -87,11 +88,11 @@ iotest!(fn timeout_success() {
|
|||||||
let port = addr.port;
|
let port = addr.port;
|
||||||
let _l = TcpListener::bind(host.as_slice(), port).unwrap().listen();
|
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() {
|
iotest!(fn timeout_error() {
|
||||||
let addr = next_test_ip4();
|
let addr = next_test_ip4();
|
||||||
|
|
||||||
assert!(TcpStream::connect_timeout(addr, 1000).is_err());
|
assert!(TcpStream::connect_timeout(addr, Duration::milliseconds(1000)).is_err());
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user