oof icon indicating copy to clipboard operation
oof copied to clipboard

Better timers

Open LuaFan2 opened this issue 5 years ago • 1 comments

The timers that are in use now are just their likeness. IMHO would be nice to make them like this:

-- Creates a simple timer that runs the given function after a specified delay. function timer.simple(delay, function) end

-- other possible function name - timer.create -- Creates a new timer that will repeat its function given amount of times. function timer.repeating(delay, repititions, function) creates and returnes TimerObject end

function TimerObject:Pause() end function TimerObject:Resume() end function TimerObject:Restart() end

-- Returns amount of repetitions/executions left before the timer destroys itself. function TimerObject():RespLeft() end

function TimerObject:Adjust(delay, repititions, function) end function TimerObject:Destroy() end

I think everyone agrees that such timers will save a lot of effort.

LuaFan2 avatar Aug 17 '20 14:08 LuaFan2

Good idea, but I don't think it's fit for the Timer class. The Timer class is specifically for timing things - the changes suggested here do not time anything, but rather provide utility for callbacks after a specific amount of time, either once or on an interval. I think it'd be better to have another class for these types of operations, named Callback or similar.

benank avatar Aug 17 '20 16:08 benank