Skip to content

Commit a78291f

Browse files
committed
concise refresh
1 parent a2c8bf2 commit a78291f

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/viam/sdk/robot/client.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,18 +226,19 @@ void RobotClient::refresh() {
226226
void RobotClient::refresh_every() {
227227
std::unique_lock<std::mutex> lk{refresh_lock_};
228228

229-
while (true) {
230-
if (refresh_cv_.wait_for(lk, refresh_interval_) == std::cv_status::timeout) {
229+
refresh_cv_.wait_for(lk, refresh_interval_, [this] {
230+
if (should_refresh_) {
231231
try {
232232
refresh();
233233
} catch (const std::exception& e) {
234-
VIAM_SDK_LOG(warn) << "Refresh thread terminated with exception: " << e.what();
235-
break;
234+
VIAM_SDK_LOG(warn) << "Refresh thread got exception " << e.what();
235+
// TODO: maybe recoverable
236+
return true;
236237
}
237-
} else if (should_refresh_ == false) {
238-
break;
239238
}
240-
}
239+
240+
return !should_refresh_;
241+
});
241242
}
242243

243244
RobotClient::RobotClient(ViamChannel channel)

0 commit comments

Comments
 (0)