I recently added jsdocs to my project and since then I have eslint telling me that
‘await has no effect on this kind of expression’
const result = await someAsyncFunction(); // await has no effect
console.log(result.property);
Removing the await keyword however has the effect that console tries to log before result has resolved.
I know that that eslint complains because someAsncyFunction
does not return a promise itself but has async functions inside of it.
async function someAsyncFunction(){
const response = await fetch('dataset');
const anotherResponse = await fetch('anotherDataset')
const merged = combineDatasets(response, anotherResponse)
return merged;
}
Am I really supposed to wrap this function in another Promise?
async function someAsyncFunction(){
return new Promise(async(resolve) => {
...
resolve(merged);
})
}
Ignoring the warning about ‘await having no effect’ works without problems – every time. How ever it makes me think that my approach and / or my understanding of promises is way of.
Maybe you could point me in the right direction here.