Sfoglia il codice sorgente

replaced missing TimerQueue

Nicolas Cannasse 13 anni fa
parent
commit
49a5e1c1a7

+ 18 - 5
std/haxe/remoting/FlashJsConnection.hx

@@ -34,7 +34,8 @@ class FlashJsConnection #if flash implements AsyncConnection, implements Dynamic
 		name : String,
 		ctx : Context,
 		error : Dynamic -> Void,
-		queue : haxe.TimerQueue,
+		timer : haxe.Timer,
+		queue : Array<Void -> Void>,
 	};
 
 	function new( data, path ) {
@@ -61,9 +62,8 @@ class FlashJsConnection #if flash implements AsyncConnection, implements Dynamic
 		s.serialize(params);
 		var params = escapeString(s.toString());
 		var error = __data.error;
-		var me = this;
-		__data.queue.add(function() {
-			var data = flash.external.ExternalInterface.call("haxe.remoting.FlashJsConnection.flashCall",me.__data.id,me.__data.name,me.__path.join("."),params);
+		__data.queue.push(function() {
+			var data = flash.external.ExternalInterface.call("haxe.remoting.FlashJsConnection.flashCall",__data.id,__data.name,__path.join("."),params);
 			var v : Dynamic;
 			try {
 				if( data == null )
@@ -76,6 +76,18 @@ class FlashJsConnection #if flash implements AsyncConnection, implements Dynamic
 			if( onResult != null )
 				onResult(v);
 		});
+		if( __data.timer == null ) {
+			__data.timer = new haxe.Timer(1);
+			__data.timer.run = function() {
+				var q = __data.queue.shift();
+				if( q == null ) {
+					__data.timer.stop();
+					__data.timer = null;
+					return;
+				}
+				q();
+			};
+		}
 	}
 
 	static var connections = new Hash<FlashJsConnection>();
@@ -121,7 +133,8 @@ class FlashJsConnection #if flash implements AsyncConnection, implements Dynamic
 			name : name,
 			ctx : ctx,
 			error : function(e) throw e,
-			queue : new haxe.TimerQueue(),
+			queue : [],
+			timer : null,
 		},[]);
 		connections.set(name,cnx);
 		return cnx;

+ 17 - 3
std/haxe/remoting/SocketConnection.hx

@@ -35,7 +35,8 @@ class SocketConnection implements AsyncConnection, implements Dynamic<AsyncConne
 		error : Dynamic -> Void,
 		#if !flash9
 		#if (flash || js)
-		queue : haxe.TimerQueue,
+		queue : Array<Void -> Void>,
+		timer : haxe.Timer,
 		#end
 		#end
 	};
@@ -131,7 +132,8 @@ class SocketConnection implements AsyncConnection, implements Dynamic<AsyncConne
 			log : null,
 			#if !flash9
 			#if (flash || js)
-			queue : new haxe.TimerQueue(),
+			queue : [],
+			timer : null,
 			#end
 			#end
 		};
@@ -154,7 +156,7 @@ class SocketConnection implements AsyncConnection, implements Dynamic<AsyncConne
 		// where a new onData is called is a parallel thread
 		// ...with the buffer of the previous onData (!)
 		s.onData = function( data : String ) {
-			sc.__data.queue.add(function() {
+			sc.__data.queue.push(function() {
 				var msgLen = sc.__data.protocol.messageLength(data.charCodeAt(0),data.charCodeAt(1));
 				if( msgLen == null || data.length != msgLen - 1 ) {
 					sc.__data.error("Invalid message header");
@@ -162,6 +164,18 @@ class SocketConnection implements AsyncConnection, implements Dynamic<AsyncConne
 				}
 				sc.processMessage(data.substr(2,data.length-2));
 			});
+			if( sc.__data.timer == null ) {
+				sc.__data.timer = new haxe.Timer(1);
+				sc.__data.timer.run = function() {
+					var q = sc.__data.queue.shift();
+					if( q == null ) {
+						sc.__data.timer.stop();
+						sc.__data.timer = null;
+						return;
+					}
+					q();
+				};
+			}
 		};
 		#end
 		return sc;