Skip to content

Commit 0a4ef06

Browse files
simbleauSpencer C. Imbleauranile
authored
gloo_timers, ambiguous verbage (#255)
* Closes #254, Documentation updates * Improvements to #254 * Update crates/timers/src/callback.rs Co-authored-by: Muhammad Hamza <[email protected]> * Update crates/timers/src/callback.rs Co-authored-by: Muhammad Hamza <[email protected]> * Update crates/timers/src/callback.rs Co-authored-by: Muhammad Hamza <[email protected]> * Update callback.rs Co-authored-by: Spencer C. Imbleau <[email protected]> Co-authored-by: Muhammad Hamza <[email protected]>
1 parent 1cd7b5c commit 0a4ef06

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

crates/timers/src/callback.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ extern "C" {
2323
///
2424
/// See `Timeout::new` for scheduling new timeouts.
2525
///
26-
/// Once scheduled, you can either `cancel` so that it doesn't run or `forget`
27-
/// it so that it is un-cancel-able.
26+
/// Once scheduled, you can [`drop`] the [`Timeout`] to clear it or [`forget`](Timeout::forget) to leak it. Once forgotten, the interval will keep running forever.
27+
/// This pattern is known as Resource Acquisition Is Initialization (RAII).
2828
#[derive(Debug)]
2929
#[must_use = "timeouts cancel on drop; either call `forget` or `drop` explicitly"]
3030
pub struct Timeout {
@@ -33,6 +33,8 @@ pub struct Timeout {
3333
}
3434

3535
impl Drop for Timeout {
36+
/// Disposes of the timeout, dually cancelling this timeout by calling
37+
/// `clearTimeout` directly.
3638
fn drop(&mut self) {
3739
if let Some(id) = self.id {
3840
clear_timeout(id);
@@ -71,7 +73,7 @@ impl Timeout {
7173
}
7274
}
7375

74-
/// Make this timeout uncancel-able.
76+
/// Forgets this resource without clearing the timeout.
7577
///
7678
/// Returns the identifier returned by the original `setTimeout` call, and
7779
/// therefore you can still cancel the timeout by calling `clearTimeout`
@@ -123,8 +125,8 @@ impl Timeout {
123125
///
124126
/// See `Interval::new` for scheduling new intervals.
125127
///
126-
/// Once scheduled, you can either `cancel` so that it ceases to fire or `forget`
127-
/// it so that it is un-cancel-able.
128+
/// Once scheduled, you can [`drop`] the [`Interval`] to clear it or [`forget`](Interval::forget) to leak it. Once forgotten, the interval will keep running forever.
129+
/// This pattern is known as Resource Acquisition Is Initialization (RAII).
128130
#[derive(Debug)]
129131
#[must_use = "intervals cancel on drop; either call `forget` or `drop` explicitly"]
130132
pub struct Interval {
@@ -133,6 +135,8 @@ pub struct Interval {
133135
}
134136

135137
impl Drop for Interval {
138+
/// Disposes of the interval, dually cancelling this interval by calling
139+
/// `clearInterval` directly.
136140
fn drop(&mut self) {
137141
if let Some(id) = self.id {
138142
clear_interval(id);
@@ -170,7 +174,7 @@ impl Interval {
170174
}
171175
}
172176

173-
/// Make this interval uncancel-able.
177+
/// Forget this resource without clearing the interval.
174178
///
175179
/// Returns the identifier returned by the original `setInterval` call, and
176180
/// therefore you can still cancel the interval by calling `clearInterval`

0 commit comments

Comments
 (0)