Upgrade to ExtJS 3.0.0 - Released 07/06/2009
[extjs.git] / source / util / TaskMgr.js
diff --git a/source/util/TaskMgr.js b/source/util/TaskMgr.js
deleted file mode 100644 (file)
index 3628421..0000000
+++ /dev/null
@@ -1,163 +0,0 @@
-/*\r
- * Ext JS Library 2.2.1\r
- * Copyright(c) 2006-2009, Ext JS, LLC.\r
- * licensing@extjs.com\r
- * \r
- * http://extjs.com/license\r
- */\r
-\r
-/**\r
- * @class Ext.util.TaskRunner\r
- * Provides the ability to execute one or more arbitrary tasks in a multithreaded manner.  Generally, you can use\r
- * the singleton {@link Ext.TaskMgr} instead, but if needed, you can create separate instances of TaskRunner.  Any\r
- * number of separate tasks can be started at any time and will run independently of each other.  Example usage:\r
- * <pre><code>\r
-// Start a simple clock task that updates a div once per second\r
-var task = {\r
-    run: function(){\r
-        Ext.fly('clock').update(new Date().format('g:i:s A'));\r
-    },\r
-    interval: 1000 //1 second\r
-}\r
-var runner = new Ext.util.TaskRunner();\r
-runner.start(task);\r
-</code></pre>\r
- * @constructor\r
- * @param {Number} interval (optional) The minimum precision in milliseconds supported by this TaskRunner instance\r
- * (defaults to 10)\r
- */\r
-Ext.util.TaskRunner = function(interval){\r
-    interval = interval || 10;\r
-    var tasks = [], removeQueue = [];\r
-    var id = 0;\r
-    var running = false;\r
-\r
-    // private\r
-    var stopThread = function(){\r
-        running = false;\r
-        clearInterval(id);\r
-        id = 0;\r
-    };\r
-\r
-    // private\r
-    var startThread = function(){\r
-        if(!running){\r
-            running = true;\r
-            id = setInterval(runTasks, interval);\r
-        }\r
-    };\r
-\r
-    // private\r
-    var removeTask = function(t){\r
-        removeQueue.push(t);\r
-        if(t.onStop){\r
-            t.onStop.apply(t.scope || t);\r
-        }\r
-    };\r
-\r
-    // private\r
-    var runTasks = function(){\r
-        if(removeQueue.length > 0){\r
-            for(var i = 0, len = removeQueue.length; i < len; i++){\r
-                tasks.remove(removeQueue[i]);\r
-            }\r
-            removeQueue = [];\r
-            if(tasks.length < 1){\r
-                stopThread();\r
-                return;\r
-            }\r
-        }\r
-        var now = new Date().getTime();\r
-        for(var i = 0, len = tasks.length; i < len; ++i){\r
-            var t = tasks[i];\r
-            var itime = now - t.taskRunTime;\r
-            if(t.interval <= itime){\r
-                var rt = t.run.apply(t.scope || t, t.args || [++t.taskRunCount]);\r
-                t.taskRunTime = now;\r
-                if(rt === false || t.taskRunCount === t.repeat){\r
-                    removeTask(t);\r
-                    return;\r
-                }\r
-            }\r
-            if(t.duration && t.duration <= (now - t.taskStartTime)){\r
-                removeTask(t);\r
-            }\r
-        }\r
-    };\r
-\r
-    /**\r
-     * @member Ext.util.TaskRunner\r
-     * @method start\r
-     * Starts a new task.\r
-     * @param {Object} task A config object that supports the following properties:<ul>\r
-     * <li><code>run</code> : Function<div class="sub-desc">The function to execute each time the task is run. The\r
-     * function will be called at each interval and passed the <code>args</code> argument if specified.  If a\r
-     * particular scope is required, be sure to specify it using the <code>scope</scope> argument.</div></li>\r
-     * <li><code>interval</code> : Number<div class="sub-desc">The frequency in milliseconds with which the task\r
-     * should be executed.</div></li>\r
-     * <li><code>args</code> : Array<div class="sub-desc">(optional) An array of arguments to be passed to the function\r
-     * specified by <code>run</code>.</div></li>\r
-     * <li><code>scope</code> : Object<div class="sub-desc">(optional) The scope in which to execute the\r
-     * <code>run</code> function.</div></li>\r
-     * <li><code>duration</code> : Number<div class="sub-desc">(optional) The length of time in milliseconds to execute\r
-     * the task before stopping automatically (defaults to indefinite).</div></li>\r
-     * <li><code>repeat</code> : Number<div class="sub-desc">(optional) The number of times to execute the task before\r
-     * stopping automatically (defaults to indefinite).</div></li>\r
-     * </ul>\r
-     * @return {Object} The task\r
-     */\r
-    this.start = function(task){\r
-        tasks.push(task);\r
-        task.taskStartTime = new Date().getTime();\r
-        task.taskRunTime = 0;\r
-        task.taskRunCount = 0;\r
-        startThread();\r
-        return task;\r
-    };\r
-\r
-    /**\r
-     * @member Ext.util.TaskRunner\r
-     * @method stop\r
-     * Stops an existing running task.\r
-     * @param {Object} task The task to stop\r
-     * @return {Object} The task\r
-     */\r
-    this.stop = function(task){\r
-        removeTask(task);\r
-        return task;\r
-    };\r
-\r
-    /**\r
-     * @member Ext.util.TaskRunner\r
-     * @method stopAll\r
-     * Stops all tasks that are currently running.\r
-     */\r
-    this.stopAll = function(){\r
-        stopThread();\r
-        for(var i = 0, len = tasks.length; i < len; i++){\r
-            if(tasks[i].onStop){\r
-                tasks[i].onStop();\r
-            }\r
-        }\r
-        tasks = [];\r
-        removeQueue = [];\r
-    };\r
-};\r
-\r
-/**\r
- * @class Ext.TaskMgr\r
- * A static {@link Ext.util.TaskRunner} instance that can be used to start and stop arbitrary tasks.  See\r
- * {@link Ext.util.TaskRunner} for supported methods and task config properties.\r
- * <pre><code>\r
-// Start a simple clock task that updates a div once per second\r
-var task = {\r
-    run: function(){\r
-        Ext.fly('clock').update(new Date().format('g:i:s A'));\r
-    },\r
-    interval: 1000 //1 second\r
-}\r
-Ext.TaskMgr.start(task);\r
-</code></pre>\r
- * @singleton\r
- */\r
-Ext.TaskMgr = new Ext.util.TaskRunner();
\ No newline at end of file