big leaps in git engine

This commit is contained in:
Peter Cottle 2012-08-15 13:05:43 -07:00
parent 21d204df92
commit 2cd620de27
4 changed files with 209 additions and 83 deletions

View file

@ -2,9 +2,69 @@
* Util classes
*/
function CommandQueue() {
this.commands = [];
this.consumeTimeout = null;
/*
var e = sys.addEdge(node1, node2);
this.initialDelay = 400;
}
CommandQueue.prototype.add = function(command) {
this.commands.push(command);
this.touchTimer();
};
CommandQueue.prototype.touchTimer = function() {
if (this.consumeTimeout) {
return;
}
this.consumeTimeout = setTimeout(_.bind(function() {
this.next();
}, this), this.initialDelay);
};
CommandQueue.prototype.reset = function() {
this.consumeTimeout = null;
};
CommandQueue.prototype.next = function() {
if (this.commands.length == 0) {
this.reset();
return;
}
// execute the top command by passing it into the engine
var toExecute = this.commands.shift(0);
var callback = _.bind(function() {
this.next();
}, this);
gitEngine.execute(toExecute, callback);
};
/******************
* Planning:
here is the major flow:
someone types in a command ->
make a new command object. if error, give immediate feedback, dont append to queue
if not error ->
append command object to queue
Command Queue ->
consume commands at a certain rate (either instantly if just added, or with an interval
Execute command -> (usually a git engine thing)
Wait for git engine command to finish
when done, execute next command (if more)
so two levels of Async-ness:
command queue slowly consumes commands
GitEngine executes commands, which will have async bits to them (such as popping off commits for a
rebase)
*/
function Scheduler(closures, options) {