[Opensrf-commits] r2008 - trunk/src/javascript (erickson)

svn at svn.open-ils.org svn at svn.open-ils.org
Wed Aug 18 16:11:23 EDT 2010


Author: erickson
Date: 2010-08-18 16:11:18 -0400 (Wed, 18 Aug 2010)
New Revision: 2008

Modified:
   trunk/src/javascript/opensrf.js
Log:

Due to the async nature of xmllhttprequest, processing http responses (which often lead to further async-request laden callbacks) at receive time can result in out-of-order message handling.  To bring order to this chaos, push all inbound message onto a queue, then go back to processing the older messages in order of oldest to newest.  



Modified: trunk/src/javascript/opensrf.js
===================================================================
--- trunk/src/javascript/opensrf.js	2010-08-16 16:27:32 UTC (rev 2007)
+++ trunk/src/javascript/opensrf.js	2010-08-18 20:11:18 UTC (rev 2008)
@@ -245,13 +245,24 @@
 OpenSRF.Stack = function() {
 }
 
+// global inbound message queue
+OpenSRF.Stack.queue = [];
+
 OpenSRF.Stack.push = function(net_msg, callbacks) {
     var ses = OpenSRF.Session.find_session(net_msg.thread); 
     if(!ses) return;
     ses.remote_id = net_msg.from;
     osrf_msgs = JSON2js(net_msg.body);
-    for(var i = 0; i < osrf_msgs.length; i++) 
-        OpenSRF.Stack.handle_message(ses, osrf_msgs[i], callbacks);        
+
+    // push the latest responses onto the end of the inbound message queue
+    for(var i = 0; i < osrf_msgs.length; i++)
+        OpenSRF.Stack.queue.push({msg : osrf_msgs[i], callbacks : callbacks});
+
+    // continue processing responses, oldest to newest
+    while(OpenSRF.Stack.queue.length) {
+        var data = OpenSRF.Stack.queue.shift();
+        OpenSRF.Stack.handle_message(ses, data.msg, data.callbacks);
+    }
 }
 
 OpenSRF.Stack.handle_message = function(ses, osrf_msg, callbacks) {



More information about the opensrf-commits mailing list