mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-01-23 07:26:54 +00:00
Added support for asynchronous commands
This commit is contained in:
parent
0784d9754c
commit
95807ea75a
@ -37,6 +37,7 @@ Commander.prototype.execute = function() {
|
|||||||
Execute the next command in the sequence
|
Execute the next command in the sequence
|
||||||
*/
|
*/
|
||||||
Commander.prototype.executeNextCommand = function() {
|
Commander.prototype.executeNextCommand = function() {
|
||||||
|
var self = this;
|
||||||
// Invoke the callback if there are no more commands
|
// Invoke the callback if there are no more commands
|
||||||
if(this.nextToken >= this.commandTokens.length) {
|
if(this.nextToken >= this.commandTokens.length) {
|
||||||
this.callback(null);
|
this.callback(null);
|
||||||
@ -54,21 +55,36 @@ Commander.prototype.executeNextCommand = function() {
|
|||||||
params.push(this.commandTokens[this.nextToken++]);
|
params.push(this.commandTokens[this.nextToken++]);
|
||||||
}
|
}
|
||||||
// Get the command info
|
// Get the command info
|
||||||
var command = $tw.commands[commandName];
|
var command = $tw.commands[commandName],
|
||||||
|
c,err;
|
||||||
if(!command) {
|
if(!command) {
|
||||||
this.callback("Unknown command: " + commandName);
|
this.callback("Unknown command: " + commandName);
|
||||||
} else {
|
} else {
|
||||||
|
if(this.verbose) {
|
||||||
|
this.streams.output.write("Executing command: " + commandName + " " + params.join(" ") + "\n");
|
||||||
|
}
|
||||||
if(command.info.synchronous) {
|
if(command.info.synchronous) {
|
||||||
if(this.verbose) {
|
// Synchronous command
|
||||||
this.streams.output.write("Executing command: " + commandName + " " + params.join(" ") + "\n");
|
c = new command.Command(params,this);
|
||||||
}
|
err = c.execute();
|
||||||
var c = new command.Command(params,this),
|
|
||||||
err = c.execute();
|
|
||||||
if(err) {
|
if(err) {
|
||||||
this.callback(err);
|
this.callback(err);
|
||||||
} else {
|
} else {
|
||||||
this.executeNextCommand();
|
this.executeNextCommand();
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// Asynchronous command
|
||||||
|
c = new command.Command(params,this,function(err) {
|
||||||
|
if(err) {
|
||||||
|
self.callback(err);
|
||||||
|
} else {
|
||||||
|
self.executeNextCommand();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
err = c.execute();
|
||||||
|
if(err) {
|
||||||
|
this.callback(err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user