Skip to content

Commit f38636b

Browse files
committed
Use SteadyTime for next_block_for
1 parent d66ee29 commit f38636b

2 files changed

Lines changed: 5 additions & 8 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ default = ["uuid"]
2626
phf = "0.5"
2727
phf_mac = "0.5"
2828
openssl = "0.2.16"
29-
time = "0.1"
29+
time = "0.1.14"
3030
log = "0.1"
3131
rustc-serialize = "0.2"
3232

src/lib.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ use std::io::net::ip::Port;
7777
use std::mem;
7878
use std::result;
7979
use std::time::Duration;
80-
use url::Url;
80+
use time::SteadyTime;
8181

82+
use url::Url;
8283
pub use error::{Error, ConnectError, SqlState, DbError, ErrorPosition};
8384
#[doc(inline)]
8485
pub use types::{Oid, Type, ToSql, FromSql};
@@ -297,20 +298,16 @@ impl<'conn> Notifications<'conn> {
297298
/// }
298299
/// ```
299300
pub fn next_block_for(&mut self, timeout: Duration) -> Result<Notification> {
300-
fn now() -> i64 {
301-
(time::precise_time_ns() / 100_000) as i64
302-
}
303-
304301
if let Some(notification) = self.next() {
305302
return Ok(notification);
306303
}
307304

308305
let mut conn = self.conn.conn.borrow_mut();
309306
check_desync!(conn);
310307

311-
let end = now() + timeout.num_milliseconds();
308+
let end = SteadyTime::now() + timeout;
312309
loop {
313-
let timeout = max(0, end - now()) as u64;
310+
let timeout = max(Duration::zero(), end - SteadyTime::now()).num_milliseconds() as u64;
314311
conn.stream.set_read_timeout(Some(timeout));
315312
match conn.read_one_message() {
316313
Ok(Some(NotificationResponse { pid, channel, payload })) => {

0 commit comments

Comments
 (0)