I have a database with text entries. I want to search for the city name, and return the country.
I have an async function which returns a thenable promise.
getText('New').then(alert(result));
After an await on a 2nd function, I want to resolve the promise with one item from the object found. i.e. TheText .
I have this code:
getText=async()=>{
const TheData=await getDataSet('City','New York'); //{country:'USA',city:'New York}
const TheText=TheData['country']; //'USA'
return new Promise((resolve,reject)=>{
const request=??;
request.onsuccess=()=>{resolve(TheText)};);
}
How can I modify the code above to return TheText as a resolved thenable promise.
TheText, wouldn't yourgetTextfunction simply return it? What is the purpose of constructing a Promise at that point? Can you clarify the underlying problem you're trying to solve?Promiseat all. If the goal is to returnTheTextfrom the function then why not simplyreturn TheText;?If I use "await" then the calling function needs to be async. And the function calling that function needs to be async. etcThat's correct and cannot be avoided. It's promises all the way down.GetValue? Where are you awaiting that? Do you meangetText? If you can't useawaiton it then you can follow it with a.then()callback, exactly like the code you've already written demonstrates. So... why doesn't that work for you? What's the actual problem you encounter?