different timeout for different xhrIo.send() in goog.net.XhrManager

113 views
Skip to first unread message

lanny

unread,
Aug 1, 2012, 10:02:34 AM8/1/12
to closure-lib...@googlegroups.com

when using goog.net.XhrManager, is it possible to set different timeout for different request?

it does have a timeoutInterval_ which could be changed before putting the request in queue. but the concern is what if when de-queue the request for sending (when the goog.net.XhrManager.prototype.handleAvailableXhr_() is called) the timeoutInterval_ has been changed by the later enqueue-ed request?

is the using multiple goog.net.XhrManager instance (let each one have its own timeout) the right way to handle this case?
Thanks!

Rhys Brett-Bowen

unread,
Aug 2, 2012, 1:28:30 PM8/2/12
to closure-lib...@googlegroups.com
this seems to be the place where the timeout is set for individual XHR calls: goog.net.XhrManager.prototype.handleAvailableXhr_

and you'll probably want to send the timeout in the send method: goog.net.XhrManager.prototype.send

you do get passed the id in the handleAvailableXhr_ and you pass in an id in the send, so for send you can do something like:


goog.net.XhrManager.prototype.send = function( id, url, opt_method, opt_content, opt_headers, opt_priority, opt_callback, opt_maxRetries, opt_timeout) {
  goog.base(this, 'send', id, url, opt_method, opt_content, opt_headers, opt_priority, opt_callback, opt_maxRetries);
  if(!this.timeouts_)
    this.timeouts = {};
  this.timeouts.id = opt_timeout;
}

you would then need to copy most of handleAvailableXhr_ and change the setting of timeout:

goog.net.XhrManager.prototype.handleAvailableXhr_ = function(id, xhrIo) { var request = this.requests_.get(id); // Make sure the request doesn't already have an XhrIo attached. This can // happen if a forced abort occurs before an XhrIo is available, and a new // request with the same id is made. if (request && !request.xhrIo) { this.addXhrListener_(xhrIo, request.getXhrEventCallback()); // Set properties for the XhrIo. 
 
xhrIo.setTimeoutInterval(this.timeouts.id || this.timeoutInterval_);

 // Add a reference to the XhrIo object to the request. request.xhrIo = request.xhrLite = xhrIo; // Notify the listeners. this.dispatchEvent(new goog.net.XhrManager.Event( goog.net.EventType.READY, this, id, xhrIo)); // Send the request. this.retry_(id, xhrIo); // If the request was aborted before it got an XhrIo object, abort it now. if (request.getAborted()) { xhrIo.abort(); } } else { // If the request has an XhrIo object already, or no request exists, just // return the XhrIo back to the pool. this.xhrPool_.releaseObject(xhrIo); } };

the point of xhrManager is to use it's xhrPool so using several would defeat the purpose. Best to extend it to work the way you want
Reply all
Reply to author
Forward
0 new messages