Bladeren bron

use timer queue

Nicolas Cannasse 18 jaren geleden
bovenliggende
commit
4bbac22bf1
4 gewijzigde bestanden met toevoegingen van 11 en 18 verwijderingen
  1. 2 0
      doc/CHANGES.txt
  2. 6 8
      std/haxe/Timer.hx
  3. 1 6
      std/haxe/remoting/FlashJsConnection.hx
  4. 2 4
      std/haxe/remoting/SocketConnection.hx

+ 2 - 0
doc/CHANGES.txt

@@ -3,6 +3,8 @@
 	fixed "Not_found" when enum params differs
 	added "override" for AS3 generator
 	fixed stack overflow in typedefs
+	added haxe.Timer.queue, removed delayedArg (use callback instead)
+	fixed haxe.remoting.SocketConnection (msg invertions might occur)
 
 2007-03-06: 1.12
 	added flash lite support with -D flash_lite

+ 6 - 8
std/haxe/Timer.hx

@@ -74,14 +74,12 @@ class Timer {
 		};
 	}
 
-	public static function delayedArg<T>( f : T -> Void, time : Int ) : T -> Void {
-		return function(arg) {
-			var t = new haxe.Timer(time);
-			t.run = function() {
-				t.stop();
-				f(arg);
-			};
-		};
+	private static var fqueue = new Array<Void -> Void>();
+	public static function queue( f : Void -> Void, ?time : Int ) : Void {
+		fqueue.push(f);
+		haxe.Timer.delayed(function() {
+			fqueue.shift()();
+		},if( time == null ) 0 else time);
 	}
 
 	public static function stamp() : Float {

+ 1 - 6
std/haxe/remoting/FlashJsConnection.hx

@@ -4,8 +4,6 @@ class FlashJsConnection extends haxe.remoting.AsyncConnection {
 
 	#if flash
 
-	static var pendingCalls = new Array();
-
 	override function __resolve( field : String ) : AsyncConnection {
 		var c = new FlashJsConnection(__data,__path.copy());
 		c.__error = __error;
@@ -22,7 +20,7 @@ class FlashJsConnection extends haxe.remoting.AsyncConnection {
 		var cnx : { private function escapeString(s : String) : String; } = haxe.remoting.Connection;
 		var params = cnx.escapeString(s.toString());
 		var me = this;
-		pendingCalls.push(function() {
+		haxe.Timer.queue(function() {
 			var s = flash.external.ExternalInterface.call("haxe.remoting.FlashJsConnection.flashCall",me.__data,path,f,params);
 			var v = null;
 			try {
@@ -35,9 +33,6 @@ class FlashJsConnection extends haxe.remoting.AsyncConnection {
 			if( v != null )
 				onData(v.r);
 		});
-		haxe.Timer.delayed(function() {
-			pendingCalls.shift()();
-		},0)();
 	}
 
 	public static function flashConnect( objId : String ) : AsyncConnection {

+ 2 - 4
std/haxe/remoting/SocketConnection.hx

@@ -269,14 +269,12 @@ class SocketConnection extends AsyncConnection {
 		// where a new onData is called is a parallel thread
 		// ...with the buffer of the previous onData (!)
 		s.onData = function(data : String) {
-			var t = new haxe.Timer(0);
-			t.run = function() {
-				t.stop();
+			haxe.Timer.queue(function() {
 				var e = processMessage(sc,data.substr(2,data.length-2));
 				// error happened in response handler, not in request
 				if( e != null )
 					throw e.exc;
-			};
+			});
 		};
 		#end
 		return sc;