Permalink
Browse files

Added wrapper functions around setImmediate and setTimeout.

  • Loading branch information...
1 parent 2ce832e commit bc177acea738e18fe0e869e3097db5a3819c7efe @solmsted committed Oct 12, 2012
Showing with 7 additions and 5 deletions.
  1. +7 −5 src/yui/js/yui-soon.js
View
@@ -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 () {
@@ -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';
}
@@ -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';
}

0 comments on commit bc177ac

Please sign in to comment.