Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,9 +550,12 @@ impl Client {

watcher.request_immediate_check();

let change_occurred = start_time.elapsed() < timeout
let elapsed = start_time.elapsed();
let change_occurred = elapsed < timeout
&& watcher
.wait_for_update(timeout - start_time.elapsed())
.wait_for_update(
timeout.checked_sub(elapsed).unwrap_or(Duration::ZERO),
)
.await;
if !change_occurred {
let error: Error = ErrorKind::ServerSelection {
Expand Down Expand Up @@ -613,10 +616,10 @@ impl Client {
if let Some(desc) = topology.description.primary() {
return Some(desc.clone());
}
if !watcher
.wait_for_update(timeout - start_time.elapsed())
.await
{
let remaining = timeout
.checked_sub(start_time.elapsed())
.unwrap_or(Duration::ZERO);
if !watcher.wait_for_update(remaining).await {
return None;
}
}
Expand Down