--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
Unfortunately, this has broken my application (it uses timers do test
network latency). Can anyone point me to a spec or the commit where
this change was made so I can see the exact limits and modify my code
to work with it? Is there any way to detect if my page is in a
foreground or background tab?
I'm trying to write a web app so the server can very rapidly determine
when a client goes offline. To do this, I hold a Websocket (falling
back to flash XMLSocket) connection open and send a byte every 250ms.
When the server doesn't get a byte after say 500ms, it assumes the
client is dead, and informs all it's other users that a client has
gone down.
For everyone else solving similar problems, here is a workaround:
Old code:
function process() {
// Do stuff...
setTimeout(process, 250);
}
New code:
function process() {
if (Now() - lastRunTime >= 250) {
lastRunTime = Now();
// Do stuff...
for (i=0; i<10; i++)
setTimeout(process, i*250);
}
}
The aim is to start lots of timers with various intervals, and if a
timer fires early ignore it. The minimum timer interval is 1 second,
but a timer with interval 1.5 seconds started 1.25 seconds ago is
still useful! The loop is required since we don't know the minimum
timer interval. Note in this design, the timer in fact fires much
more frequently than required, but for most firings the "IF" statement
means nothing is done. A more advanced design could start all the
timers and keep track of them all and cancel unnecessary ones.
New code:
function process() {
if (Now() - lastRunTime >= 250) {
lastRunTime = Now();
// Do stuff...
for (i=0; i<10; i++)
setTimeout(process, i*250);
}
}
The aim is to start lots of timers with various intervals, and if a
timer fires early ignore it. The minimum timer interval is 1 second,
but a timer with interval 1.5 seconds started 1.25 seconds ago is
still useful!
I'm afraid there isn't a spec for this change. As I recall, the once
per second number was chosen largely because it matched the behavior
of Mozilla's mozRequestAnimationFrame API for background tabs at the
time.
The final commit implementing this change was
http://codereview.chromium.org/6577021 . There were several previous
commits to WebKit and Chromium which put the infrastructure in place,
and at least one follow-on bug fix.
-Ken