package kernel; import cc.OS; using tink.CoreApi; /** Wrapper class for using timer. **/ class Timer { private final timerID:Int; private final callback:Callback; private final timerLink:CallbackLink; /** Create new timer with timeout in seconds. **/ public function new(timeout:Float, callback:Callback) { timerID = OS.startTimer(timeout); this.callback = callback; timerLink = KernelEvents.instance.onTimer.handle(timerID -> { if (this.timerID == timerID) { callback.invoke(null); timerLink.cancel(); } }); } /** Cancle timer. **/ public function cancle() { OS.cancelTimer(timerID); timerLink.cancel(); } }