Skip to content

Commit 5b60f96

Browse files
committed
fix(ProgressLogger): add refresh interval setter
1 parent 9496026 commit 5b60f96

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

include/geode/basic/progress_logger.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
#include <geode/basic/common.hpp>
2929
#include <geode/basic/pimpl.hpp>
3030

31+
namespace absl
32+
{
33+
class Duration;
34+
} // namespace absl
35+
3136
namespace geode
3237
{
3338
class opengeode_basic_api ProgressLogger
@@ -44,6 +49,8 @@ namespace geode
4449

4550
index_t increment_nb_steps( index_t nb_steps );
4651

52+
void set_refresh_interval( absl::Duration refresh_interval );
53+
4754
private:
4855
IMPLEMENTATION_MEMBER( impl_ );
4956
};

src/geode/basic/progress_logger.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@
3232
#include <geode/basic/progress_logger_manager.hpp>
3333
#include <geode/basic/uuid.hpp>
3434

35-
namespace
36-
{
37-
constexpr absl::Duration SLEEP = absl::Seconds( 1 );
38-
} // namespace
39-
4035
namespace geode
4136
{
4237
class ProgressLogger::Impl
@@ -65,7 +60,7 @@ namespace geode
6560
const std::lock_guard< std::mutex > locking{ lock_ };
6661
current_ += nb_increments;
6762
auto now = absl::Now();
68-
if( now - current_time_ > SLEEP )
63+
if( now - current_time_ > refresh_interval_ )
6964
{
7065
current_time_ = now;
7166
ProgressLoggerManager::update( id_, current_, nb_steps_ );
@@ -80,12 +75,18 @@ namespace geode
8075
return nb_steps_;
8176
}
8277

78+
void set_refresh_interval( absl::Duration refresh_interval )
79+
{
80+
refresh_interval_ = std::move( refresh_interval );
81+
}
82+
8383
private:
8484
uuid id_;
8585
index_t nb_steps_;
8686
index_t current_{ 0 };
8787
absl::Time current_time_;
8888
std::mutex lock_;
89+
absl::Duration refresh_interval_{ absl::Seconds( 1 ) };
8990
};
9091

9192
ProgressLogger::ProgressLogger(
@@ -115,4 +116,9 @@ namespace geode
115116
{
116117
return impl_->increment_nb_steps( nb_steps );
117118
}
119+
120+
void ProgressLogger::set_refresh_interval( absl::Duration refresh_interval )
121+
{
122+
impl_->set_refresh_interval( std::move( refresh_interval ) );
123+
}
118124
} // namespace geode

0 commit comments

Comments
 (0)