1 // Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 use option::{Option, Some, None};
12 use result::{Ok, Err};
13 use rt::io::{io_error};
14 use rt::rtio::{IoFactory, IoFactoryObject,
15 RtioTimer, RtioTimerObject};
18 pub struct Timer(~RtioTimerObject);
21 fn new_on_rt(i: ~RtioTimerObject) -> Timer {
25 pub fn new() -> Option<Timer> {
27 rtdebug!("Timer::init: borrowing io to init timer");
28 let io = Local::unsafe_borrow::<IoFactoryObject>();
29 rtdebug!("about to init timer");
33 Ok(t) => Some(Timer::new_on_rt(t)),
35 rtdebug!("Timer::init: failed to init: %?", ioerr);
36 io_error::cond.raise(ioerr);
43 impl RtioTimer for Timer {
44 fn sleep(&self, msecs: u64) {
45 (**self).sleep(msecs);
53 use option::{Some, None};
55 fn test_io_timer_sleep_simple() {
56 do run_in_newsched_task {
57 let timer = Timer::new();
59 Some(t) => t.sleep(1),
60 None => assert!(false)