I have been given the task of reading a file, processing the data and returning the results. As it is an async process, I run into the problem where you cannot return from a .then, and an unresolved Promise is unresolved. I am using fetch. I know this issue has been discussed a lot, apologies. Here is code. Thank you.
function myFunction () {
async function fetchData() {
await fetch("./my_file.txt")
.then((res) => res.text())
.then((text) => {
//I want to return text here
})
.catch((e) => console.error(e));
}
const response = fetchData();
//I can process the data here and then return it
//process data
//return results
}
Try something like this: