New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Meteor.defer in inactive iOS tabs. #1023

Closed
wants to merge 1 commit into
base: devel
from

Conversation

Projects
None yet
2 participants
@awwx
Contributor

awwx commented May 7, 2013

In iOS Safari, setTimeout and setInterval events are not delivered
to inactive tabs (unless and until they become active again). This
means that using setTimeout(fn, 0) to run fn in the next event
loop can in fact delay fn indefinitely.

This implementation uses the native setImmediate (when available) or
postMessage (all other modern browsers); falling back to
setTimeout if the first two aren't available.

The qa subdirectory includes a manual test to check that defer is
working in inactive tabs. (Sadly the test can't run automatically
because scripts aren't allowed to open child windows except in
response to user events).

Factors out some common code in timers.js.

Support Meteor.defer in inactive iOS tabs.
In iOS Safari, `setTimeout` and `setInterval` events are not delivered
to inactive tabs (unless and until they become active again).  This
means that using `setTimeout(fn, 0)` to run `fn` in the next event
loop can in fact delay `fn` indefinitely.

This implementation uses the native `setImmediate` (when available) or
`postMessage` (all other modern browsers); falling back to
`setTimeout` if the first two aren't available.

The `qa` subdirectory includes a manual test to check that `defer` is
working in inactive tabs.  (Sadly the test can't run automatically
because scripts aren't allowed to open child windows except in
response to user events).

Factors out some common code in `timers.js`.
@awwx

This comment has been minimized.

Contributor

awwx commented May 7, 2013

I ended up just using the postMessage implementation from https://github.com/NobleJS/setImmediate . That polyfill was doing a lot of work to fulfill the spec... which both was doing things we didn't want or didn't need, and which has been rejected by everyone else besides Microsoft (other browsers haven't implemented the spec, and Node has a setImmediate in its latest version but it doesn't try to do all the stuff the spec says). We don't need a polyfill anyway since our public API is Meteor.defer.

@n1mmy

This comment has been minimized.

Member

n1mmy commented May 23, 2013

Nice work. Merged. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment