Skip to content

Commit 2015811

Browse files
committed
fix: Periodic timers were being removed.
1 parent 3b968e7 commit 2015811

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

include/net/timers/impl/timers_impl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ auto timers<Interrupt>::resolve() -> duration
251251
if (event.period.count() == 0)
252252
event.armed.clear();
253253

254-
return event.armed.test();
254+
return !event.armed.test();
255255
});
256256

257257
return with_lock(std::unique_lock(mtx_), [&] {

tests/test_timers.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,16 @@ TEST(TimersTests, ReuseTimerID)
7777
auto timer1 = timers.add(100, [](timer_id) {});
7878
EXPECT_EQ(timer0, timer1);
7979
}
80+
81+
TEST(TimersTests, PeriodicTimer)
82+
{
83+
using namespace std::chrono;
84+
85+
auto timers = timers_type();
86+
auto timer0 = timers.add(100, [](timer_id) {}, 100);
87+
ASSERT_EQ(timer0, 0);
88+
std::this_thread::sleep_for(milliseconds(1));
89+
auto next = timers.resolve();
90+
EXPECT_NE(next.count(), -1);
91+
}
8092
// NOLINTEND

0 commit comments

Comments
 (0)