Skip to content

Commit

Permalink
Avoid promise chaining when possible (#1902)
Browse files Browse the repository at this point in the history
  • Loading branch information
aweebit committed Jul 24, 2023
1 parent 96b9fc2 commit 62700a3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,8 @@ Expecting one of '${allowedValues.join("', '")}'`);
_awaitHookPreSubcommand() {
this.hook('preSubcommand', () => {
if (this._shouldAwait()) {
return Promise.all(this._getOptionPromises());
const toAwait = this._getOptionPromises();
if (toAwait.length) return Promise.all(toAwait);
}
});
}
Expand All @@ -499,7 +500,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
}
});

return Promise.all(toAwait);
if (toAwait.length) return Promise.all(toAwait);
}
});
}
Expand Down
1 change: 0 additions & 1 deletion tests/command.hook.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ describe('action hooks async', () => {
const calls = [];
const program = new commander.Command();
program
.awaitHook(false)
.hook('postAction', async() => {
await 0;
calls.push('after');
Expand Down

0 comments on commit 62700a3

Please sign in to comment.