Răsfoiți Sursa

imediately cancel previous event in EventLoop upon MainLoop.add (fixes #10329)

Aleksandr Kuzmenko 4 ani în urmă
părinte
comite
3247dc4a64

+ 3 - 3
std/haxe/MainLoop.hx

@@ -110,11 +110,11 @@ class MainLoop {
 	static function injectIntoEventLoop(waitMs:Int) {
 		#if (target.threaded && !cppia)
 			mutex.acquire();
+			if(eventLoopHandler != null)
+				mainThread.events.cancel(eventLoopHandler);
 			eventLoopHandler = mainThread.events.repeat(
 				() -> {
-					if(eventLoopHandler != null) {
-						mainThread.events.cancel(eventLoopHandler);
-					}
+					mainThread.events.cancel(eventLoopHandler);
 					var wait = tick();
 					if(hasEvents()) {
 						injectIntoEventLoop(Std.int(wait * 1000));

+ 14 - 0
tests/misc/compiler_loops/projects/Issue10329/Main.hx

@@ -0,0 +1,14 @@
+import haxe.MainLoop;
+
+class Main {
+	static function main() {
+		var e1 = null;
+		var e2 = null;
+		e1 = MainLoop.add(() -> {
+			e1.stop();
+		});
+		e2 = MainLoop.add(() -> {
+			e2.stop();
+		});
+	}
+}

+ 2 - 0
tests/misc/compiler_loops/projects/Issue10329/compile.hxml

@@ -0,0 +1,2 @@
+--main Main
+--interp