Skip to content

Commit 2f8dafe

Browse files
committed
Add some more docs and comments to SleepTracker.
1 parent 6bd1209 commit 2f8dafe

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/cargo/util/network/sleep.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,19 @@ use core::cmp::Ordering;
44
use std::collections::BinaryHeap;
55
use std::time::{Duration, Instant};
66

7+
/// A tracker for network requests that have failed, and are awaiting to be
8+
/// retried in the future.
79
pub struct SleepTracker<T> {
10+
/// This is a priority queue that tracks the time when the next sleeper
11+
/// should awaken (based on the [`Sleeper::wakeup`] property).
812
heap: BinaryHeap<Sleeper<T>>,
913
}
1014

15+
/// An individual network request that is waiting to be retried in the future.
1116
struct Sleeper<T> {
17+
/// The time when this requests should be retried.
1218
wakeup: Instant,
19+
/// Information about the network request.
1320
data: T,
1421
}
1522

@@ -21,6 +28,8 @@ impl<T> PartialEq for Sleeper<T> {
2128

2229
impl<T> PartialOrd for Sleeper<T> {
2330
fn partial_cmp(&self, other: &Sleeper<T>) -> Option<Ordering> {
31+
// This reverses the comparison so that the BinaryHeap tracks the
32+
// entry with the *lowest* wakeup time.
2433
Some(other.wakeup.cmp(&self.wakeup))
2534
}
2635
}

0 commit comments

Comments
 (0)