diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2013-12-12 17:30:41 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2013-12-24 14:42:00 -0800 |
| commit | 4538369566b8b51fc8371253aa90f9725547a193 (patch) | |
| tree | dd3390d2083e2a6d5c494dec6760bdf4590a8b86 /src/libstd/io/timer.rs | |
| parent | a55c57284d8341ee5b22c5372e77ac0af9479dc5 (diff) | |
| download | rust-4538369566b8b51fc8371253aa90f9725547a193.tar.gz rust-4538369566b8b51fc8371253aa90f9725547a193.zip | |
std: Expose that LocalIo may not always be available
It is not the case that all programs will always be able to acquire an instance of the LocalIo borrow, so this commit exposes this limitation by returning Option<LocalIo> from LocalIo::borrow(). At the same time, a helper method LocalIo::maybe_raise() has been added in order to encapsulate the functionality of raising on io_error if there is on local I/O available.
Diffstat (limited to 'src/libstd/io/timer.rs')
| -rw-r--r-- | src/libstd/io/timer.rs | 14 |
1 files changed, 2 insertions, 12 deletions
diff --git a/src/libstd/io/timer.rs b/src/libstd/io/timer.rs index c86e1a1890b..7c9aa28bfe9 100644 --- a/src/libstd/io/timer.rs +++ b/src/libstd/io/timer.rs @@ -39,9 +39,7 @@ loop { */ use comm::Port; -use option::{Option, Some, None}; -use result::{Ok, Err}; -use io::io_error; +use option::Option; use rt::rtio::{IoFactory, LocalIo, RtioTimer}; pub struct Timer { @@ -60,15 +58,7 @@ impl Timer { /// for a number of milliseconds, or to possibly create channels which will /// get notified after an amount of time has passed. pub fn new() -> Option<Timer> { - let mut io = LocalIo::borrow(); - match io.get().timer_init() { - Ok(t) => Some(Timer { obj: t }), - Err(ioerr) => { - debug!("Timer::init: failed to init: {:?}", ioerr); - io_error::cond.raise(ioerr); - None - } - } + LocalIo::maybe_raise(|io| io.timer_init().map(|t| Timer { obj: t })) } /// Blocks the current task for `msecs` milliseconds. |
