Вы можете вернуть результат Promise
из вызова verifyEmp().then()
(так как async
функции возвращают Promise
) из первого find().then
обратного вызова.
Там вы можете передать и результат вызова verifyEmp()
, а также объект emp
из текущей области, обернутый в другом объекте, к следующему then
в цепочке.
Promise
из verifyEmp().then()
автоматически разворачивается в следующем then
обратном вызове в цепочке:
var verifyEmp = async function () {
return 'Verified';
}
const Employee = {
find: async function(email, password){
return {email, password, "id":123};
}
}
Employee.find("test@abc.com", "test")
.then((emp) => {
//This promise woud get unwrapped in the next .then callback
return verifyEmp()
.then((msg) => ({emp,msg}));
})
.then((msg) => {
console.log(msg);
})
.catch((err) => {
console.error(err);
})