package kernel; using tink.CoreApi; import cc.OS; /** 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:Int, 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(); } }