I have an issue with Node Async Await and recursive functions. For some reason, the code execution stops after resolving the Promise for a recursive function. Below is just a simple example I put in to demonstrate my issue (though found the problem while sending some requests with requests library).
If you run the code, you will see
Starting
Inside Promise
but not "Test Completed".
function promiseFunc(number) {
return new Promise((resolve, reject) => {
if (number == 100) {
console.log('Inside Promise');
resolve('Done');
} else {
number += 1
promiseFunc(number);
}
})
}
(async function testFunc() {
console.log('Starting');
await promiseFunc(0)
console.log("Test completed");
})()
Could someone please advise what is the issue?
Thank you in advance.
new Promise()runs 101 times, aresolve()runs once. See the problem?