Skip to content

Commit

Permalink
Replace forEach
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowspawn committed Jul 27, 2023
1 parent a3c4cd3 commit 6fd35d2
Showing 1 changed file with 13 additions and 21 deletions.
34 changes: 13 additions & 21 deletions lib/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -1277,18 +1277,14 @@ Expecting one of '${allowedValues.join("', '")}'`);
*/

_settleOptionPromises() {
const promises = [];

// Look through the options for promises from async parseArgs (or other sources).
Object.entries(this.opts()).forEach(([key, value]) => {
if (thenable(value)) {
// Resave value after promise resolves.
const promise = value.then((settledValue) => {
this.setOptionValueWithSource(key, settledValue, this.getOptionValueSource(key));
const promises = Object.entries(this.opts())
.filter(([key, maybePromise]) => thenable(maybePromise))
.map(([key, promise]) => {
return promise.then(value => {
this.setOptionValueWithSource(key, value, this.getOptionValueSource(key));
});
promises.push(promise);
}
});
});

if (promises.length > 0) {
return Promise.all(promises);
Expand All @@ -1300,18 +1296,14 @@ Expecting one of '${allowedValues.join("', '")}'`);
*/

_settleArgumentPromises() {
const promises = [];

// Variadic array is either ordinary, or a promise for an array.
this.processedArgs.forEach((arg, index) => {
if (thenable(arg)) {
// Resave value after promise resolves.
const promise = arg.then((settledArg) => {
this.processedArgs[index] = settledArg;
// Look through the arguments for promises from async parseArgs (or other sources).
const promises = this.processedArgs
.filter(thenable)
.map((promise, index) => {
return promise.then(value => {
this.processedArgs[index] = value;
});
promises.push(promise);
}
});
});

if (promises.length > 0) {
return Promise.all(promises);
Expand Down

0 comments on commit 6fd35d2

Please sign in to comment.