X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/ee06f37b0f6f6d94cd05a6ffae556660f7c4a2bc..c930e9176a5a85509c5b0230e2bff5c22a591432:/source/util/TaskMgr.js diff --git a/source/util/TaskMgr.js b/source/util/TaskMgr.js deleted file mode 100644 index 36284214..00000000 --- a/source/util/TaskMgr.js +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Ext JS Library 2.2.1 - * Copyright(c) 2006-2009, Ext JS, LLC. - * licensing@extjs.com - * - * http://extjs.com/license - */ - -/** - * @class Ext.util.TaskRunner - * Provides the ability to execute one or more arbitrary tasks in a multithreaded manner. Generally, you can use - * the singleton {@link Ext.TaskMgr} instead, but if needed, you can create separate instances of TaskRunner. Any - * number of separate tasks can be started at any time and will run independently of each other. Example usage: - *
-// Start a simple clock task that updates a div once per second
-var task = {
- run: function(){
- Ext.fly('clock').update(new Date().format('g:i:s A'));
- },
- interval: 1000 //1 second
-}
-var runner = new Ext.util.TaskRunner();
-runner.start(task);
-
- * @constructor
- * @param {Number} interval (optional) The minimum precision in milliseconds supported by this TaskRunner instance
- * (defaults to 10)
- */
-Ext.util.TaskRunner = function(interval){
- interval = interval || 10;
- var tasks = [], removeQueue = [];
- var id = 0;
- var running = false;
-
- // private
- var stopThread = function(){
- running = false;
- clearInterval(id);
- id = 0;
- };
-
- // private
- var startThread = function(){
- if(!running){
- running = true;
- id = setInterval(runTasks, interval);
- }
- };
-
- // private
- var removeTask = function(t){
- removeQueue.push(t);
- if(t.onStop){
- t.onStop.apply(t.scope || t);
- }
- };
-
- // private
- var runTasks = function(){
- if(removeQueue.length > 0){
- for(var i = 0, len = removeQueue.length; i < len; i++){
- tasks.remove(removeQueue[i]);
- }
- removeQueue = [];
- if(tasks.length < 1){
- stopThread();
- return;
- }
- }
- var now = new Date().getTime();
- for(var i = 0, len = tasks.length; i < len; ++i){
- var t = tasks[i];
- var itime = now - t.taskRunTime;
- if(t.interval <= itime){
- var rt = t.run.apply(t.scope || t, t.args || [++t.taskRunCount]);
- t.taskRunTime = now;
- if(rt === false || t.taskRunCount === t.repeat){
- removeTask(t);
- return;
- }
- }
- if(t.duration && t.duration <= (now - t.taskStartTime)){
- removeTask(t);
- }
- }
- };
-
- /**
- * @member Ext.util.TaskRunner
- * @method start
- * Starts a new task.
- * @param {Object} task A config object that supports the following properties:run
: Functionargs
argument if specified. If a
- * particular scope is required, be sure to specify it using the scope argument.
interval
: Numberargs
: Arrayrun
.scope
: Objectrun
function.duration
: Numberrepeat
: Number
-// Start a simple clock task that updates a div once per second
-var task = {
- run: function(){
- Ext.fly('clock').update(new Date().format('g:i:s A'));
- },
- interval: 1000 //1 second
-}
-Ext.TaskMgr.start(task);
-
- * @singleton
- */
-Ext.TaskMgr = new Ext.util.TaskRunner();
\ No newline at end of file