API C Timer.NewTicker

NewTicker extends by returning a handle that responds to   and repeating for a number of iterations. NewTimer constructs a ticker without repetition. handle = C_Timer.NewTimer(duration, callback) handle = C_Timer.NewTicker(duration, callback [, iterations])

Arguments

 * duration : - Seconds between each iteration (resolution limited by framerate)
 * callback : - What you want to execute each iteration
 * iterations : - Number of times to repeat, or indefinite if omitted.

Returns

 * handle : - Reference to a ticker with two methods, Cancel and IsCancelled

Details

 * NewTimer presently calls  but a comment in the source code warns this could change
 * The source code also warns that tickers are less efficient than, so should only be used if the added features are desired
 * Cancelling a ticker during a callback function will prevent future iterations, but not stop the current execution from finishing
 * Errors thrown during a callback function will automatically stop the ticker from future iterations

Examples
The following example illustrates the utility of each function -- call myFunc in 1 sec C_Timer.After(1, myFunc) -- call myFunc in 5 sec, but cancel it right away local myTimer = C_Timer.NewTimer(5, myFunc) print(myTimer:IsCancelled) -- "false" myTimer:Cancel print(myTimer:IsCancelled) -- "true" -- call myFunc every 0.1 sec, ten times, but cancel it right away local myTicker = C_Timer.NewTicker(0.1, myFunc, 10) myTicker:Cancel