All pastes #956266 Raw Edit

Thread.Simple

public javascript v1 · immutable
#956266 ·published 2008-03-25 03:47 UTC
rendered paste body
Thread.Simple.prototype = $.extend({}, Thread.prototype);$.extend(Thread.Simple.prototype, {	addTask: function(item) {		this._data.push(item);		return this;	},	_tasks: 0,	_numTasks: 0,	run: function() {		var data = this._data.pop();		if (data)			this._run(data);		else			return true; // All tasks completed		// Complete a task		if (this._tasks < this._numTasks) {			this._tasks++;			// We can run more tasks per "thread call"; may be slow on large data sets			// due to recursive functions behavior in JavaScript.			return this.run();		}		this._tasks = 0;		return false;	}});