package kernel; import cc.OS; /** Make sure that a function is called at the end of the current event loop. Like setTimeout(func, 0) in JavaScript. **/ class EndOfLoop { private static var backlog:ArrayVoid> = []; private static var isQueued = false; public static function endOfLoop(func:Void->Void) { backlog.push(func); if (!isQueued) { OS.queueEvent("endofloop", null); } } @:allow(kernel.KernelEvents) private static function run() { for (func in backlog) { func(); } backlog = []; isQueued = false; } }