Created
January 15, 2019 08:41
-
-
Save sincerefly/9d2c276a954847c261392b56d4b97314 to your computer and use it in GitHub Desktop.
使用Async方式处理接受Promise结果可以省去then接收结果,更为方便
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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