File tree 2 files changed +20
-3
lines changed
2 files changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ use std::mem::ManuallyDrop;
5
5
use std:: os:: raw:: c_void;
6
6
use std:: ptr;
7
7
use std:: sync:: Arc ;
8
- use std:: time:: Duration ;
8
+ use std:: time:: { Duration , Instant } ;
9
9
10
10
use log:: { error, warn} ;
11
11
use rdkafka_sys as rdsys;
@@ -123,6 +123,7 @@ where
123
123
queue : & NativeQueue ,
124
124
timeout : T ,
125
125
) -> Option < KafkaResult < BorrowedMessage < ' _ > > > {
126
+ let now = Instant :: now ( ) ;
126
127
let mut timeout = timeout. into ( ) ;
127
128
let min_poll_interval = self . context ( ) . main_queue_min_poll_interval ( ) ;
128
129
loop {
@@ -158,10 +159,10 @@ where
158
159
}
159
160
}
160
161
161
- if op_timeout >= timeout {
162
+ timeout = timeout. saturating_sub ( now. elapsed ( ) ) ;
163
+ if timeout. is_zero ( ) {
162
164
return None ;
163
165
}
164
- timeout -= op_timeout;
165
166
}
166
167
}
167
168
Original file line number Diff line number Diff line change @@ -48,6 +48,22 @@ impl Timeout {
48
48
Timeout :: Never => -1 ,
49
49
}
50
50
}
51
+
52
+ /// Saturating `Duration` subtraction to Timeout.
53
+ pub ( crate ) fn saturating_sub ( & self , rhs : Duration ) -> Timeout {
54
+ match ( self , rhs) {
55
+ ( Timeout :: After ( lhs) , rhs) => Timeout :: After ( lhs. saturating_sub ( rhs) ) ,
56
+ ( Timeout :: Never , _) => Timeout :: Never ,
57
+ }
58
+ }
59
+
60
+ /// Returns `true` if the timeout is zero.
61
+ pub ( crate ) fn is_zero ( & self ) -> bool {
62
+ match self {
63
+ Timeout :: After ( d) => d. is_zero ( ) ,
64
+ Timeout :: Never => false ,
65
+ }
66
+ }
51
67
}
52
68
53
69
impl std:: ops:: SubAssign for Timeout {
You can’t perform that action at this time.
0 commit comments