This is because your loop generates new promises, which is allowed asycnoursly, use Promise.all
when you need to run multiple promises:
For instance:
if (object.email !== undefined) {
return Promise.all(object.email.map( emailObject => {
if(emailObject){
return this.isEmailUnsubscribed(emailObject, options)
}else{
return Promise.resolve()
}
} ))
.then(emailObjects => {
object.email = emailObjects
console.log('Email Objects from rules.evaluate')
console.log(emailObjects)
this.sendEmailToSelectedUsers(object, options)
})
}
source
share