From 35a028b6253a38d00c16dca2a36b69c5888c022a Mon Sep 17 00:00:00 2001 From: John Gee Date: Tue, 9 Nov 2021 18:37:07 +1300 Subject: [PATCH] Wrap emit to preserve callback order when async (#1638) --- lib/command.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/command.js b/lib/command.js index 4756cf5a0..695c840ec 100644 --- a/lib/command.js +++ b/lib/command.js @@ -1225,7 +1225,11 @@ Expecting one of '${allowedValues.join("', '")}'`); let actionResult; actionResult = this._chainOrCallHooks(actionResult, 'preAction'); actionResult = this._chainOrCall(actionResult, () => this._actionHandler(this.processedArgs)); - if (this.parent) this.parent.emit(commandEvent, operands, unknown); // legacy + if (this.parent) { + actionResult = this._chainOrCall(actionResult, () => { + this.parent.emit(commandEvent, operands, unknown); // legacy + }); + } actionResult = this._chainOrCallHooks(actionResult, 'postAction'); return actionResult; }