File tree Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -4,12 +4,19 @@ use core::cmp::Ordering;
4
4
use std:: collections:: BinaryHeap ;
5
5
use std:: time:: { Duration , Instant } ;
6
6
7
+ /// A tracker for network requests that have failed, and are awaiting to be
8
+ /// retried in the future.
7
9
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).
8
12
heap : BinaryHeap < Sleeper < T > > ,
9
13
}
10
14
15
+ /// An individual network request that is waiting to be retried in the future.
11
16
struct Sleeper < T > {
17
+ /// The time when this requests should be retried.
12
18
wakeup : Instant ,
19
+ /// Information about the network request.
13
20
data : T ,
14
21
}
15
22
@@ -21,6 +28,8 @@ impl<T> PartialEq for Sleeper<T> {
21
28
22
29
impl < T > PartialOrd for Sleeper < T > {
23
30
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.
24
33
Some ( other. wakeup . cmp ( & self . wakeup ) )
25
34
}
26
35
}
You can’t perform that action at this time.
0 commit comments