2
0
Nicolas Cannasse 8 жил өмнө
parent
commit
f3bce934d9
2 өөрчлөгдсөн 14 нэмэгдсэн , 1 устгасан
  1. 12 0
      std/hl/uv/Loop.hx
  2. 2 1
      std/hl/uv/Tcp.hx

+ 12 - 0
std/hl/uv/Loop.hx

@@ -28,4 +28,16 @@ abstract Loop(hl.Abstract<"uv_loop">) {
 		return null;
 	}
 
+	/**
+		Register the default loop into the main haxe loop.
+		Should be called at least once unless you want to integrate the loop update yourself.
+	**/
+	public static function register() {
+		if( initDone ) return;
+		initDone = true;
+		var def = getDefault();
+		haxe.MainLoop.add(function() def.run(NoWait));
+	}
+	static var initDone = false;
+
 }

+ 2 - 1
std/hl/uv/Tcp.hx

@@ -3,7 +3,8 @@ package hl.uv;
 @:hlNative("uv")
 class Tcp extends Stream {
 
-	public function new( loop : Loop ) {
+	public function new( ?loop : Loop ) {
+		if( loop == null ) loop = Loop.getDefault();
 		super(tcp_init_wrap(loop));
 	}