This is AWS Lambda function awaiting on async function. I can not get returned value. I need to do fetch data in loop as long as there are still some values on the server to be retrieved:
let do_search = true;
while (do_search) {
const url = 'xxx';
await fetchData(url)
.then(response => {
console.log("fetchData result:", response);
if (response) {
console.log("Stop searching, no more data");
do_search = false;
}
})
.....
while my fetchData returns false value when there is still more data to be processed. fetchData function:
async function fetchData(url) {
...
console.log("Returning false");
return false;
The problem is even my fetchData returns false, my log are always:
Returning false
fetchData result: true
I have also tried to use other approach with:
const createModelBInstance = async () => {
let response = await fetchData(url)
console.log("fetchData result:", response);
if (response){
do_search=false;
}
}
await createModelBInstance();
Based on some examples on this forum. But exactly same problem, my fetchData returns false while "fetchData result: true".
Any working example ? That Promise values returned are causing simple code to be very complicated :(
fetchDatacome from? Is that your code or an imported package?responseis equal totruethando_searchis going to befalse. Is that right? According to what you say it should be the opposite ifresponseis equal tofalsethando_searchisfalse. In that case you might want to do thisif(!response) ...awaitand athenhandler. Use one or the other. I also suspect your FetchData code needs to be reviewed and corrected.