Skip to content

Commit

Permalink
Added wrapper functions around setImmediate and setTimeout.
Browse files Browse the repository at this point in the history
  • Loading branch information
solmsted committed Oct 12, 2012
1 parent 2ce832e commit bc177ac
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/yui/js/yui-soon.js
Expand Up @@ -33,9 +33,7 @@ var soon = function (callbackFunction) {
if (!canceled) {
callbackFunction();
}
}, 0);
// The 0 is required when setTimeout is used, but it should be ignored
// by other asynchronizers.
});

return {
cancel: function () {
Expand Down Expand Up @@ -131,7 +129,9 @@ var soon = function (callbackFunction) {

// Check for a native or already polyfilled implementation of setImmediate.
if ('setImmediate' in Y.config.win) {
soon._asynchronizer = Y.config.win.setImmediate;
soon._asynchronizer = function (callbackFunction) {
Y.config.win.setImmediate(callbackFunction);
};
soon._impl = 'setImmediate';
}

Expand All @@ -144,7 +144,9 @@ else if (('postMessage' in Y.config.win) && !('importScripts' in Y.config.win))
// The most widely supported asynchronizer is setTimeout so we use that as the
// fallback.
else {
soon._asynchronizer = setTimeout;
soon._asynchronizer = function (callbackFunction) {
setTimeout(callbackFunction, 0);
};
soon._impl = 'setTimeout';
}

Expand Down

0 comments on commit bc177ac

Please sign in to comment.