[open-ils-commits] r11827 - trunk/Open-ILS/web/js/dojo/openils
svn at svn.open-ils.org
svn at svn.open-ils.org
Wed Jan 14 13:08:12 EST 2009
Author: erickson
Date: 2009-01-14 13:08:10 -0500 (Wed, 14 Jan 2009)
New Revision: 11827
Modified:
trunk/Open-ILS/web/js/dojo/openils/PermaCrud.js
Log:
prevent case where .recv() is called more than once on a single response. on sync calls with no response handlers, return the first value received or null is none is received
Modified: trunk/Open-ILS/web/js/dojo/openils/PermaCrud.js
===================================================================
--- trunk/Open-ILS/web/js/dojo/openils/PermaCrud.js 2009-01-14 17:21:40 UTC (rev 11826)
+++ trunk/Open-ILS/web/js/dojo/openils/PermaCrud.js 2009-01-14 18:08:10 UTC (rev 11827)
@@ -80,16 +80,23 @@
var _pcrud = this;
var req = this.session.request( req_hash );
-
if (!req.onerror)
req.onerror = function (r) { throw js2JSON(r); };
- if (!req.oncomplete)
- req.oncomplete = function (r) { r.result = r.recv(); _pcrud.last_result = r.result; };
+ // if it's an async call and the user does not care about
+ // the responses, pull them off the network and discard them
+ if (!req_hash.timeout && !req.oncomplete)
+ req.oncomplete = function (r) { while(r.recv()){}; };
req.send();
- if (req_hash.timeout) return req.recv().content();
+ // for synchronous calls with no handlers, return the first received value
+ if (req_hash.timeout && !opts.oncomplete && !opts.onresponse) {
+ var resp = req.recv();
+ if(resp) return resp.content();
+ return null;
+ }
+
return req;
},
@@ -121,13 +128,21 @@
if (!req.onerror)
req.onerror = function (r) { throw js2JSON(r); };
+
+ // if it's an async call and the user does not care about
+ // the responses, pull them off the network and discard them
+ if (!req_hash.timeout && !req.oncomplete)
+ req.oncomplete = function (r) { while(r.recv()){}; };
- if (!req.oncomplete)
- req.oncomplete = function (r) { r.result = r.recv(); _pcrud.last_result = r.result; };
-
req.send();
- if (req_hash.timeout) return req.recv().content();
+ // for synchronous calls with no handlers, return the first received value
+ if (req_hash.timeout && !opts.oncomplete && !opts.onresponse) {
+ var resp = req.recv();
+ if(resp) return resp.content();
+ return null;
+ }
+
return req;
},
@@ -155,12 +170,20 @@
if (!req.onerror)
req.onerror = function (r) { throw js2JSON(r); };
- if (!req.oncomplete)
- req.oncomplete = function (r) { r.result = r.recv(); _pcrud.last_result = r.result; };
+ // if it's an async call and the user does not care about
+ // the responses, pull them off the network and discard them
+ if (!req_hash.timeout && !req.oncomplete)
+ req.oncomplete = function (r) { while(r.recv()){}; };
req.send();
- if (req_hash.timeout) return req.recv().content();
+ // for synchronous calls with no handlers, return the first received value
+ if (req_hash.timeout && !opts.oncomplete && !opts.onresponse) {
+ var resp = req.recv();
+ if(resp) return resp.content();
+ return null;
+ }
+
return req;
},
@@ -203,7 +226,6 @@
oncomplete : function (r) {
var res = r.recv();
if ( res && res.content() ) {
- console.log(req + ' : ' + req._final_complete);
if(req._final_complete)
req._final_complete(req);
_pcrud.disconnect();
More information about the open-ils-commits
mailing list