Properly avoiding garbage collection of a timer #3434
Replies: 2 comments 2 replies
-
There certainly needs to be some way to hang on to a reference to the timer, to protect it from GC. I take your point about potentially needing multiple instances of "the same" timer, and I note that timer callbacks currently receive zero arguments... We could start passing the timer object to the callback. This would let you have a single global table that you insert new timers into, and then when the callbacks determine the timer is finished with, they are able to remove themselves from that table. Would that fit your needs? |
Beta Was this translation helpful? Give feedback.
-
Slightly simpler? globalTimers = {}
globalTimers.tooBright = hs.timer.doAfter(1, function()
doDockActions({"keylight"},force)
globalTimers.tooBright = nil
end) |
Beta Was this translation helpful? Give feedback.
-
Say I need a long timer which I need to make sure isn't garbage collected, and I also don't want to use a global variable because I may add more than one of these timers for whatever purpose in a function, is this really how intricate it has to be? This can't be made simpler?
Beta Was this translation helpful? Give feedback.
All reactions