From 6e493755bea4273e40c3bb54e3d680a395d827a0 Mon Sep 17 00:00:00 2001 From: Arlen Beiler <439872+Arlen22@users.noreply.github.com> Date: Thu, 9 Oct 2025 11:06:03 -0400 Subject: [PATCH] Add support for commands and startups which return promises (#9103) --- boot/boot.js | 10 ++++++---- core-server/commander.js | 12 ++++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/boot/boot.js b/boot/boot.js index 0c7828abd..fb728bc13 100644 --- a/boot/boot.js +++ b/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; diff --git a/core-server/commander.js b/core-server/commander.js index b73e39b0f..a6cdc81c9 100644 --- a/core-server/commander.js +++ b/core-server/commander.js @@ -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); } }