From 2084c2226e58455a216f0cff6a704e4b6481b992 Mon Sep 17 00:00:00 2001 From: erickson Date: Wed, 14 Jan 2009 18:08:10 +0000 Subject: [PATCH] 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 git-svn-id: svn://svn.open-ils.org/ILS/trunk@11827 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/web/js/dojo/openils/PermaCrud.js | 46 +++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/Open-ILS/web/js/dojo/openils/PermaCrud.js b/Open-ILS/web/js/dojo/openils/PermaCrud.js index 61e5178b50..909a667f27 100644 --- a/Open-ILS/web/js/dojo/openils/PermaCrud.js +++ b/Open-ILS/web/js/dojo/openils/PermaCrud.js @@ -80,16 +80,23 @@ if(!dojo._hasResource["openils.PermaCrud"]) { 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(!dojo._hasResource["openils.PermaCrud"]) { 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; }, @@ -155,12 +170,20 @@ if(!dojo._hasResource["openils.PermaCrud"]) { 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 @@ if(!dojo._hasResource["openils.PermaCrud"]) { 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(); -- 2.11.0