Skip to content

Instantly share code, notes, and snippets.

@sincerefly
Created January 15, 2019 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sincerefly/9d2c276a954847c261392b56d4b97314 to your computer and use it in GitHub Desktop.
Save sincerefly/9d2c276a954847c261392b56d4b97314 to your computer and use it in GitHub Desktop.
使用Async方式处理接受Promise结果可以省去then接收结果,更为方便
const bcrypt = require('bcrypt');
const NUM_SALT_ROUNDS = 8;
async function test() {
const pws = ["passwd", "passwd2", "passed3"];
const promises = pws.map(pw => bcrypt.hash(pw, NUM_SALT_ROUNDS));
const result = await Promise.all(promises);
console.log(result);
}
function test2() {
const pws = ["passwd", "passwd2", "passed3"];
const promises = pws.map(pw => bcrypt.hash(pw, NUM_SALT_ROUNDS));
Promise.all(promises).then(result => {
console.log(result);
});
}
test();
test2();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment