Skip to content

Commit

Permalink
Made code faster by removing moot await
Browse files Browse the repository at this point in the history
  • Loading branch information
leo committed Mar 21, 2017
1 parent b190c0f commit 9c280f8
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 28 deletions.
3 changes: 1 addition & 2 deletions bin/now-alias.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,7 @@ async function confirmDeploymentRemoval(alias, _alias) {
const msg = '> The following alias will be removed permanently\n' +
` ${tbl} \nAre you sure?`;

const prompted = await promptBool(msg);
return prompted;
return promptBool(msg);
}

function findAlias(alias, list) {
Expand Down
4 changes: 1 addition & 3 deletions lib/alias.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ module.exports = class Alias extends Now {

async updatePathBasedroutes(alias, rules) {
alias = await this.maybeSetUpDomain(alias);
const upsert = await this.upsertPathAlias(alias, rules);

return upsert;
return this.upsertPathAlias(alias, rules);
}

async upsertPathAlias(alias, rules) {
Expand Down
3 changes: 1 addition & 2 deletions lib/domains.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ const domainRegex = /^((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-

module.exports = class Domains extends Now {
async ls() {
const domains = await this.listDomains();
return domains;
return this.listDomains();
}

async rm(name) {
Expand Down
11 changes: 1 addition & 10 deletions lib/get-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,16 +306,7 @@ async function explode(paths, { accepts, debug }) {
return path;
};

const many = async all => {
const awaitAll = await Promise.all(
all.map(async file => {
const listed = await list(file);
return listed;
})
);

return awaitAll;
};
const many = async all => Promise.all(all.map(async file => list(file)));

return flatten(await many(paths)).filter(v => v !== null);
}
Expand Down
7 changes: 2 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ module.exports = class Now extends EventEmitter {
Array.from(this._files).map(async ([sha, { data, names }]) => {
const statFn = followSymlinks ? stat : lstat;

const nameList = await names.map(async name => {
return names.map(async name => {
let mode;

const getMode = async () => {
Expand All @@ -164,8 +164,6 @@ module.exports = class Now extends EventEmitter {
mode
};
});

return nameList;
})
)
)
Expand Down Expand Up @@ -473,8 +471,7 @@ module.exports = class Now extends EventEmitter {
console.timeEnd(`> [debug] #${attempt} GET /domains/${domain}`);
}

const parsedJSON = await res.json();
return parsedJSON;
return res.json();
});
}

Expand Down
7 changes: 2 additions & 5 deletions lib/plans.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ async function parsePlan(res) {
module.exports = class Plans extends Now {
async getCurrent() {
const res = await this._fetch('/www/user/plan');

const parsedPlan = await parsePlan(res);
return parsedPlan;
return parsePlan(res);
}

async set(plan) {
Expand All @@ -39,8 +37,7 @@ module.exports = class Plans extends Now {
});

if (res.ok) {
const parsedPlan = await parsePlan(res);
return parsedPlan;
return parsePlan(res);
}

const err = new Error(res.statusText);
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
]
},
"xo": {
"space": true,
"ignores": [
"test/_fixtures/**"
],
Expand Down

0 comments on commit 9c280f8

Please sign in to comment.