diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2013-10-25 21:55:10 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2013-10-25 22:12:55 -0700 |
| commit | 7a1d97e62cd467596457d850fd5e73f6160159c2 (patch) | |
| tree | db458c437467ccc81610a13ea48fe551ca3c57e1 /src/libstd/rt/uv | |
| parent | baeed886aa64943ad48121cc3b57dabec12bc835 (diff) | |
Enhance timers to create ports
In addition to being able to sleep the current task, timers should be able to create ports which get notified after a period of time. Closes #10014
Diffstat (limited to 'src/libstd/rt/uv')
| -rw-r--r-- | src/libstd/rt/uv/uvio.rs | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/src/libstd/rt/uv/uvio.rs b/src/libstd/rt/uv/uvio.rs index 6709f0bff44..2f8dacc4339 100644 --- a/src/libstd/rt/uv/uvio.rs +++ b/src/libstd/rt/uv/uvio.rs @@ -13,7 +13,7 @@ use cast::transmute; use cast; use cell::Cell; use clone::Clone; -use comm::{SendDeferred, SharedChan}; +use comm::{SendDeferred, SharedChan, Port, PortOne, GenericChan}; use libc::{c_int, c_uint, c_void, pid_t}; use ops::Drop; use option::*; @@ -1468,6 +1468,41 @@ impl RtioTimer for UvTimer { self_.watcher.stop(); } } + + fn oneshot(&mut self, msecs: u64) -> PortOne<()> { + use comm::oneshot; + + let (port, chan) = oneshot(); + let chan = Cell::new(chan); + do self.home_for_io |self_| { + let chan = Cell::new(chan.take()); + do self_.watcher.start(msecs, 0) |_, status| { + assert!(status.is_none()); + assert!(!chan.is_empty()); + chan.take().send_deferred(()); + } + } + + return port; + } + + fn period(&mut self, msecs: u64) -> Port<()> { + use comm::stream; + + let (port, chan) = stream(); + let chan = Cell::new(chan); + do self.home_for_io |self_| { + let chan = Cell::new(chan.take()); + do self_.watcher.start(msecs, msecs) |_, status| { + assert!(status.is_none()); + do chan.with_ref |chan| { + chan.send_deferred(()); + } + } + } + + return port; + } } pub struct UvFileStream { |
