From d4f2cef44ce81e94b0a78dc4f2bb56b69a7c4fbc Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Tue, 28 Jul 2026 12:10:09 -0400 Subject: [PATCH] Resolve failure to update `time_to_next`. --- ClockReceiver/DeferredQueue.hpp | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/ClockReceiver/DeferredQueue.hpp b/ClockReceiver/DeferredQueue.hpp index ae32dedc1..62415e003 100644 --- a/ClockReceiver/DeferredQueue.hpp +++ b/ClockReceiver/DeferredQueue.hpp @@ -116,16 +116,25 @@ public: The constructor-supplied target will be called with one or more periods that add up to @c length; any scheduled actions will be called between periods. */ - void run_for(TimeUnit length) { - auto time_to_next = DeferredQueue::time_until_next_action(); - while(time_to_next != TimeUnit(-1) && time_to_next <= length) { - target_(time_to_next); - length -= time_to_next; - DeferredQueue::advance(time_to_next); - } + void run_for(const TimeUnit length) { + const auto update = [this](const TimeUnit period) { + target_(period); + DeferredQueue::advance(period); + }; - DeferredQueue::advance(length); - target_(length); + auto length_remaining = length; + while(true) { + const auto time_to_next = DeferredQueue::time_until_next_action(); + if(time_to_next == TimeUnit(-1) || time_to_next > length_remaining) { + if(length_remaining > TimeUnit(0)) { + update(length_remaining); + } + break; + } + + length_remaining -= time_to_next; + update(time_to_next); + } } private: