W3C home > Mailing lists > Public > public-webapps@w3.org > October to December 2011

Re: [XHR2] timeout

From: Glenn Maynard <glenn@zewt.org>
Date: Wed, 21 Dec 2011 14:20:21 -0500
Message-ID: <CABirCh_M8QCeXuRfOjk4SJ3O8w4OhMr7AxG-g2c8w=sVVPH97w@mail.gmail.com>
To: olli@pettay.fi
Cc: Jarred Nicholls <jarred@webkit.org>, Anne van Kesteren <annevk@opera.com>, WebApps WG <public-webapps@w3.org>
On Wed, Dec 21, 2011 at 1:34 PM, Olli Pettay <Olli.Pettay@helsinki.fi>wrote:

> xhr.onprogress = function() {
>  this.timeout += 250;
> }
>

What if a UA suspends scripts in background pages (eg. to save battery),
but allows XHR requests to continue?  This would time out as soon as that
happened.

This particular snippet seems to be trying to do work that the browser
should be taking care of.  If there's really a use case for "must receive
some data every N milliseconds", in addition to .timeout ("the whole
request must complete in N milliseconds"), then it seems better to add a
separate timeout property for that instead of encouraging people to
implement timeouts by hand.  It would also work fine for synchronous
requests.

(I don't know what the use cases are for this, though.)

On Wed, Dec 21, 2011 at 1:59 PM, Jarred Nicholls <jarred@webkit.org> wrote:
>
>
>    1. Clean code, which is better for authors and the web platform.  To
>    achieve the same results as a native dataTimeout, your snippet would need
>    to be amended to maintain the time of the start of the request and
>    calculate the difference between that and the time the progress event fired
>    + your timeout value:
>
>    xhr.timeout = ((new Date()).getTime() - requestStart) + myTimeout;
>
> This, at least, doesn't seem interesting.  I don't think it's worthwhile
to add new APIs just so people don't have to do simple math.

var now = new Date().getTime();
xhr.timeout = now - requestStart + timeoutLength;

This is simple and clean; there's no need to complicate the platform for
this.

-- 
Glenn Maynard
Received on Wednesday, 21 December 2011 19:20:56 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:49 GMT