local function OnFinished(self)
local id = self.id
if type(self.func) == "string" then
-- We manually set the unpack count to prevent issues with an arg set that contains nil and ends with nil
-- e.g. local t = {1, 2, nil, 3, nil} print(#t) will result in 2, instead of 5. This fixes said issue.
self.object[self.func](self.object, unpack(self.args, 1, self.argsCount))
else
self.func(unpack(self.args, 1, self.argsCount))
end
-- If an error happens above, the below never runs!
-- If the id is different it means that the timer was already cancelled
-- and has been used to create a new timer during the OnFinished callback.
if not self.looping and id == self.id then
activeTimers[self.id] = nil
self.args = nil
inactiveTimers[self] = true
end
end