Answer the question
In order to leave comments, you need to log in
Why is the code not executed after calling the promise and the process does not die?
const find = async function (){
try{
console.log(await Model.findOne())
console.log('after find');
}
catch (e){
console.log('find err = ' + e); // не выводится т.к. нет ошибок
}
}
find()
.then(()=>{console.log('then')})
console.log('END'); // Не выводится и процесс не завершается
Answer the question
In order to leave comments, you need to log in
Because Model.findOne() returns a promise that is never fulfilled. As a result, the await operator waits for this promise forever. Well, let him wait, all of a sudden, the promise will still someday be fulfilled, and the find () function will continue, and after it the script will end.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question