Closed hrivera2014 closed 4 years ago
If returnSomethingElse
errors, it will crash the app. There need to be a Promise or try...catch
block around it. Also returning a resolve
of a Promise alone can be written as:
return Promise.resolve(somethingElse);
But I don't see a point why you would not await
in a Promise.
Problems with error handling ? https://eslint.org/docs/rules/no-async-promise-executor
Old issue.
I was having a similar issue then I got to a stackoverflow question:https://stackoverflow.com/questions/43036229/is-it-an-anti-pattern-to-use-async-await-inside-of-a-new-promise-constructor So your code can be write so:
async function returnSomething(name) { const somethingElse = await returnSomethingElse(); return new Promise( (resolve, reject) => { resolve(somethingElse); }); } What you think guys.
Thinking a little more. What about if there are more than one asyncronous activity that need to be waited inside returnSomething function. Then I dont know how to treat these case.