mqttagent

MQTT Lua Agent
git clone https://git.instinctive.eu/mqttagent.git
Log | Files | Refs | README | LICENSE

commit ef831c88454c740546eaa1b6d0e9a3f4b563dd4b
parent 01c5818efb2e99625f581d6999cc92df42a63953
Author: Natasha Kerensikova <natgh@instinctive.eu>
Date:   Sat, 22 Feb 2025 17:48:58 +0000

Timer is updated inside runTimers()
Diffstat:
Mmqttagent.go | 16+++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/mqttagent.go b/mqttagent.go @@ -85,13 +85,7 @@ func Run(agent MqttAgent, main_script string, capacity int) { case <-timer.C: } - hasTimer, nextTimer := runTimers(L) - - if hasTimer { - timer.Reset(time.Until(nextTimer)) - } else { - timer.Stop() - } + runTimers(L, timer) if tableIsEmpty(stateCnxTable(L)) && tableIsEmpty(stateTimerTable(L)) { break @@ -536,7 +530,7 @@ func toTime(lsec lua.LNumber) time.Time { return time.Unix(sec, nsec) } -func runTimers(L *lua.LState) (bool, time.Time) { +func runTimers(L *lua.LState, parentTimer *time.Timer) { hasNext := false var nextTime time.Time @@ -562,5 +556,9 @@ func runTimers(L *lua.LState) (bool, time.Time) { timer, luaT = timers.Next(timer) } - return hasNext, nextTime + if hasNext { + parentTimer.Reset(time.Until(nextTime)) + } else { + parentTimer.Stop() + } }