[Opensrf-commits] r2009 - branches/rel_1_4/src/javascript (erickson)

svn at svn.open-ils.org svn at svn.open-ils.org
Wed Aug 18 16:12:30 EDT 2010


Author: erickson
Date: 2010-08-18 16:12:25 -0400 (Wed, 18 Aug 2010)
New Revision: 2009

Modified:
   branches/rel_1_4/src/javascript/opensrf.js
Log:
back-port 2008: async message handling ordering

Modified: branches/rel_1_4/src/javascript/opensrf.js
===================================================================
--- branches/rel_1_4/src/javascript/opensrf.js	2010-08-18 20:11:18 UTC (rev 2008)
+++ branches/rel_1_4/src/javascript/opensrf.js	2010-08-18 20:12:25 UTC (rev 2009)
@@ -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