[Xmpp4js-commit] SF.net SVN: xmpp4js: [731] trunk/src/main/javascript
Status: Beta
Brought to you by:
h-iverson
From: <h-i...@us...> - 2008-07-07 21:18:42
|
Revision: 731 http://xmpp4js.svn.sourceforge.net/xmpp4js/?rev=731&view=rev Author: h-iverson Date: 2008-07-07 14:18:33 -0700 (Mon, 07 Jul 2008) Log Message: ----------- replaced ext TaskRunner with custom, untested impl...woooo Modified Paths: -------------- trunk/src/main/javascript/adapter/Default.js trunk/src/main/javascript/transport/Base.js Modified: trunk/src/main/javascript/adapter/Default.js =================================================================== --- trunk/src/main/javascript/adapter/Default.js 2008-07-07 20:45:50 UTC (rev 730) +++ trunk/src/main/javascript/adapter/Default.js 2008-07-07 21:18:33 UTC (rev 731) @@ -337,7 +337,7 @@ if (xhr.readyState == 4 ) { var success = xhr.status == 200; - request.callback.call( request.scope, request, sucess, xhr ); + request.callback.call( request.scope, request, success, xhr ); } }; @@ -397,6 +397,65 @@ } +Soashable.Lang.TaskRunner = function(interval) { + this.interval = interval; + this.tasks = []; + + this.intervalId = setInterval(this.onInterval.bind(this), this.interval); +} +Soashable.Lang.TaskRunner.prototype = { + start: function(task) { + this.tasks.push( task ); + }, + + stop: function(task) { + var removeIdxs = []; + + for( var i = 0; i < this.tasks.length; i++ ) { + if( this.tasks[i] === task ) { + removeIdxs.push( i ); + } + } + + this.removeTasks( removeIdxs ); + }, + + removeTasks: function( removeIdxs ) { + // JS is single threaded, so this shouldn't have concurrency issues + for( var i = 0; i < removeIdxs.length; i++ ) { + var task = this.tasks[i]; + + // fire a stop event if present + if( task.onStop ) { + task.onStop.apply( task.scope ? task.scope : task ); + } + + this.tasks.splice( i, 1 ); + } + }, + + stopAll: function() { + var removeIdxs = []; + + // this is kind of stupid... + for( var i = 0; i < this.tasks.length; i++ ) { + removeIdxs.push(i); + } + + this.removeTasks( removeIdxs ); + }, + + onInterval: function() { + for( var i = 0; i < this.tasks.length; i++ ) { + var task = this.tasks[i]; + + task.run.apply( task.scope ? task.scope : task ); + } + } + +} + + Modified: trunk/src/main/javascript/transport/Base.js =================================================================== --- trunk/src/main/javascript/transport/Base.js 2008-07-07 20:45:50 UTC (rev 730) +++ trunk/src/main/javascript/transport/Base.js 2008-07-07 21:18:33 UTC (rev 731) @@ -77,15 +77,14 @@ * @type Ext.util.TaskRunner * @private */ - this.taskRunner = new Ext.util.TaskRunner(); + this.taskRunner = new Soashable.Lang.TaskRunner(500); /** * @private */ this.sendQueueTask = { scope: this, - run: this.sendQueue, - interval: 500 + run: this.sendQueue }; /** @@ -93,8 +92,7 @@ */ this.sendPollTask = { scope: this, - run: this.sendPoll, - interval: 500 + run: this.sendPoll }; /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |