Skip to content

Commit 0d94f84

Browse files
committed
---
yaml --- r: 127738 b: refs/heads/snap-stage3 c: 734834c h: refs/heads/master v: v3
1 parent b46aae8 commit 0d94f84

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 49a970f2449a78f28b6c301e542d38593094ca77
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 8a5fe8655af5b8927cb6868d715c5bd9fa30c3b3
4+
refs/heads/snap-stage3: 734834c7d6e4862c8348a8c9660bb338773047ca
55
refs/heads/try: d9c23fcbaea89871667272a67ecb8d3a512162f3
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libstd/io/timer.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,29 @@ impl Timer {
114114
/// this is called in method-chaining style, the receiver will be
115115
/// invalidated at the end of that statement, and all `recv` calls will
116116
/// fail.
117+
///
118+
/// # Example
119+
///
120+
/// ```rust
121+
/// use std::io::Timer;
122+
///
123+
/// let mut timer = Timer::new().unwrap();
124+
/// let ten_milliseconds = timer.oneshot(10);
125+
///
126+
/// for _ in range(0u, 100) { /* do work */ }
127+
///
128+
/// // blocks until 10 ms after the `oneshot` call
129+
/// ten_milliseconds.recv();
130+
/// ```
131+
///
132+
/// ```rust
133+
/// use std::io::Timer;
134+
///
135+
/// // Incorrect, method chaining-style:
136+
/// let mut five_ms = Timer::new().unwrap().oneshot(5);
137+
/// // The timer object was destroyed, so this will always fail:
138+
/// // five_ms.recv()
139+
/// ```
117140
pub fn oneshot(&mut self, duration: Duration) -> Receiver<()> {
118141
let (tx, rx) = channel();
119142
self.obj.oneshot(in_ms(duration), box TimerCallback { tx: tx });
@@ -133,6 +156,35 @@ impl Timer {
133156
/// this is called in method-chaining style, the receiver will be
134157
/// invalidated at the end of that statement, and all `recv` calls will
135158
/// fail.
159+
///
160+
/// # Example
161+
///
162+
/// ```rust
163+
/// use std::io::Timer;
164+
///
165+
/// let mut timer = Timer::new().unwrap();
166+
/// let ten_milliseconds = timer.periodic(10);
167+
///
168+
/// for _ in range(0u, 100) { /* do work */ }
169+
///
170+
/// // blocks until 10 ms after the `periodic` call
171+
/// ten_milliseconds.recv();
172+
///
173+
/// for _ in range(0u, 100) { /* do work */ }
174+
///
175+
/// // blocks until 20 ms after the `periodic` call (*not* 10ms after the
176+
/// // previous `recv`)
177+
/// ten_milliseconds.recv();
178+
/// ```
179+
///
180+
/// ```rust
181+
/// use std::io::Timer;
182+
///
183+
/// // Incorrect, method chaining-style.
184+
/// let mut five_ms = Timer::new().unwrap().periodic(5);
185+
/// // The timer object was destroyed, so this will always fail:
186+
/// // five_ms.recv()
187+
/// ```
136188
pub fn periodic(&mut self, duration: Duration) -> Receiver<()> {
137189
let (tx, rx) = channel();
138190
self.obj.period(in_ms(duration), box TimerCallback { tx: tx });

0 commit comments

Comments
 (0)