I'm doing kind of QA (Question/Answers) application using the Bluebird library. So here's the scenario:
- User fill the form with answers for some number of questions (e.g 5 questions).
- A question has more than 1 possible answer: "Question has many answers"
- Answers are encrypted (bcrypt) on database using node.bcrypt
- When looping through answers, if user answer matches, there's no need to continue checking the answer for that question.
So it's a common problem to solve when doing things synchronous, but I'm a little lost to do that async with promises.
Here's a sample of what I don't know how to proceed:
.then(function(answers) {
var compare = Promise.promisify(bcrypt.compare);
// foreach answer, I need to check like this
// compare(answer.password, user.password).then(function(match){
// if (match) break; <-- something like this
// })
})