@@ -145,10 +145,9 @@ RobotClient::~RobotClient() {
145145void RobotClient::close () {
146146 should_refresh_.store (false );
147147
148- for ( auto & thread : threads_ ) {
149- thread .join ();
148+ if (refresh_thread_. joinable () ) {
149+ refresh_thread_ .join ();
150150 }
151- threads_.clear ();
152151
153152 stop_all ();
154153
@@ -223,7 +222,7 @@ void RobotClient::refresh() {
223222void RobotClient::refresh_every () {
224223 while (should_refresh_.load ()) {
225224 try {
226- std::this_thread::sleep_for (std::chrono::seconds ( refresh_interval_) );
225+ std::this_thread::sleep_for (refresh_interval_);
227226 refresh ();
228227
229228 } catch (std::exception&) {
@@ -274,10 +273,10 @@ void RobotClient::log(const std::string& name,
274273std::shared_ptr<RobotClient> RobotClient::with_channel (ViamChannel channel,
275274 const Options& options) {
276275 auto robot = std::make_shared<RobotClient>(std::move (channel));
277- robot->refresh_interval_ = options.refresh_interval ();
278- robot->should_refresh_ = (robot->refresh_interval_ > 0 );
276+ robot->refresh_interval_ = std::chrono::seconds{ options.refresh_interval ()} ;
277+ robot->should_refresh_ = (robot->refresh_interval_ > std::chrono::seconds{ 0 } );
279278 if (robot->should_refresh_ ) {
280- robot->threads_ . emplace_back ( &RobotClient::refresh_every, robot.get ()) ;
279+ robot->refresh_thread_ = std::thread{ &RobotClient::refresh_every, robot.get ()} ;
281280 }
282281
283282 robot->refresh ();
0 commit comments