浏览代码

renamed EventLoop.js to AtomicEventLoop.js. Fixed an issue with clearImmediate

Shaddock Heath 10 年之前
父节点
当前提交
086a93b596
共有 1 个文件被更改,包括 4 次插入25 次删除
  1. 4 25
      Resources/CoreData/AtomicModules/AtomicEventLoop.js

+ 4 - 25
Resources/CoreData/AtomicModules/EventLoop.js → Resources/CoreData/AtomicModules/AtomicEventLoop.js

@@ -125,7 +125,7 @@ EventLoop.removeTimerById = function (timer_id, isImmediate) {
             // Timer on active list: mark removed (not really necessary, but
             // Timer on active list: mark removed (not really necessary, but
             // nice for dumping), and remove from active list.
             // nice for dumping), and remove from active list.
             t.removed = true;
             t.removed = true;
-            this.timers.splice(i /*start*/ , 1 /*deleteCount*/ );
+            timers.splice(i /*start*/ , 1 /*deleteCount*/ );
             return;
             return;
         }
         }
     }
     }
@@ -223,9 +223,6 @@ EventLoop.processImmediates = function () {
      *  The way we handle this is that if any setImmediates adds another setImmediate to the
      *  The way we handle this is that if any setImmediates adds another setImmediate to the
      *  list, it will wait until the end of the next cycle..not sure this is the best way to handle
      *  list, it will wait until the end of the next cycle..not sure this is the best way to handle
      *  this, but if not you could easily implement a DOS where the update handler never gets returned to
      *  this, but if not you could easily implement a DOS where the update handler never gets returned to
-     *
-     *  TODO: need to figure out how to yield between calls to setImmediate.
-     *
      */
      */
 
 
     while (sanity-- > 0) {
     while (sanity-- > 0) {
@@ -238,8 +235,6 @@ EventLoop.processImmediates = function () {
             break;
             break;
         }
         }
 
 
-        // Timers to expire?
-
         if (timers.length <= 0) {
         if (timers.length <= 0) {
             break;
             break;
         }
         }
@@ -336,14 +331,13 @@ function clearTimeout(timer_id) {
 }
 }
 
 
 /**
 /**
- * schedules a function to be called after the end of the current update cycle
+ * schedules a function to be called after the end of the current update cycle.  SetImmediate timers are processed FIFO
  * @method
  * @method
  * @param {function} func the Function to call
  * @param {function} func the Function to call
  * @param {any} [parameters] A comma separated list of parameters to pass to func
  * @param {any} [parameters] A comma separated list of parameters to pass to func
  * @returns {int} the id of the setImmediate function to be used in clearImmediate in order to cancel it.
  * @returns {int} the id of the setImmediate function to be used in clearImmediate in order to cancel it.
  */
  */
 function setImmediate(func) {
 function setImmediate(func) {
-
     var cb_func;
     var cb_func;
     var bind_args;
     var bind_args;
     var timer_id;
     var timer_id;
@@ -389,20 +383,6 @@ function clearImmediate(timer_id) {
     evloop.removeTimerById(timer_id, true);
     evloop.removeTimerById(timer_id, true);
 }
 }
 
 
-/**
- * stops a previously queued immediate function from executing
- * @method
- * @param {int} timer_id the id of the timer that was created via setImmediate
- */
-function clearImmediate(timer_id) {
-    var evloop = EventLoop;
-
-    if (typeof timer_id !== 'number') {
-        throw new TypeError('timer ID is not a number');
-    }
-    evloop.removeTimerById(timer_id, true);
-}
-
 /**
 /**
  * set up a timer that repeats every "delay" milliseconds.
  * set up a timer that repeats every "delay" milliseconds.
  * @method
  * @method
@@ -478,7 +458,7 @@ Atomic.engine.subscribeToEvent('Update', function updateTimer() {
 
 
 // Hook into the postUpdate event of the engine and process all the setImmediate calls
 // Hook into the postUpdate event of the engine and process all the setImmediate calls
 Atomic.engine.subscribeToEvent('PostUpdate', function updateImmediates() {
 Atomic.engine.subscribeToEvent('PostUpdate', function updateImmediates() {
-   EventLoop.processImmediates();
+    EventLoop.processImmediates();
 });
 });
 
 
 // Load up the global methods .  This module doesn't export anything, it just sets up the global methods.
 // Load up the global methods .  This module doesn't export anything, it just sets up the global methods.
@@ -488,9 +468,8 @@ Atomic.engine.subscribeToEvent('PostUpdate', function updateImmediates() {
     global.setTimeout = global.setTimeout || setTimeout;
     global.setTimeout = global.setTimeout || setTimeout;
     global.clearTimeout = global.clearTimeout || clearTimeout;
     global.clearTimeout = global.clearTimeout || clearTimeout;
     global.setImmediate = global.setImmediate || setImmediate;
     global.setImmediate = global.setImmediate || setImmediate;
-    global.clearImmedeate = global.clearImmediate || clearImmediate;
+    global.clearImmediate = global.clearImmediate || clearImmediate;
 
 
     global.requestEventLoopExit = global.requestEventLoopExit || requestEventLoopExit;
     global.requestEventLoopExit = global.requestEventLoopExit || requestEventLoopExit;
 })(new Function('return this')());
 })(new Function('return this')());
 
 
-module.exports = EventLoop;