mirror of
https://github.com/Jermolene/TiddlyWiki5.git
synced 2025-12-06 02:30:46 -08:00
Add support for commands and startups which return promises (#9103)
This commit is contained in:
parent
64fce62075
commit
6e493755be
2 changed files with 14 additions and 8 deletions
10
boot/boot.js
10
boot/boot.js
|
|
@ -2629,11 +2629,13 @@ $tw.boot.executeNextStartupTask = function(callback) {
|
|||
$tw.boot.log(s.join(" "));
|
||||
// Execute task
|
||||
if(!$tw.utils.hop(task,"synchronous") || task.synchronous) {
|
||||
task.startup();
|
||||
if(task.name) {
|
||||
$tw.boot.executedStartupModules[task.name] = true;
|
||||
const thenable = task.startup();
|
||||
if(thenable && typeof thenable.then === "function"){
|
||||
thenable.then(asyncTaskCallback);
|
||||
return true;
|
||||
} else {
|
||||
return asyncTaskCallback();
|
||||
}
|
||||
return $tw.boot.executeNextStartupTask(callback);
|
||||
} else {
|
||||
task.startup(asyncTaskCallback);
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -99,16 +99,18 @@ Commander.prototype.executeNextCommand = function() {
|
|||
}
|
||||
}
|
||||
if(command.info.synchronous) {
|
||||
// Synchronous command
|
||||
// Synchronous command (await thenables)
|
||||
c = new command.Command(params,this);
|
||||
err = c.execute();
|
||||
if(err) {
|
||||
if(err && typeof err.then === "function") {
|
||||
err.then(e => { e ? this.callback(e) : this.executeNextCommand(); });
|
||||
} else if(err) {
|
||||
this.callback(err);
|
||||
} else {
|
||||
this.executeNextCommand();
|
||||
}
|
||||
} else {
|
||||
// Asynchronous command
|
||||
// Asynchronous command (await thenables)
|
||||
c = new command.Command(params,this,function(err) {
|
||||
if(err) {
|
||||
self.callback(err);
|
||||
|
|
@ -117,7 +119,9 @@ Commander.prototype.executeNextCommand = function() {
|
|||
}
|
||||
});
|
||||
err = c.execute();
|
||||
if(err) {
|
||||
if(err && typeof err.then === "function") {
|
||||
err.then(e => { if(e) this.callback(e); });
|
||||
} else if(err) {
|
||||
this.callback(err);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue