I follow a lot of Javascript questions, and whenever the 'Promise' tag comes up, I'd give it an 80% chance that the OP simply does not understand how promises work.
It's very easy to find examples of this. Common patterns are:
- Nested
new Promise()
calls. - Nested
then()
calls where they are unneeded. - And the biggest red flag: Not getting that what happens in
then()
is asynchronous, so writing a function that uses promises means that the result of that function also needs to be a promise.
Luckily, for most of these questions there are people that take the time to help answer with the specific issue.
However, all these really fall into a common category. If a member of my team would have questions like it, I would probably want them to first go out and read up on the subject before continuing. Promises really seem like such a fundamental part of modern Javascript, that (to me) it kinda falls into a category of knowledge that you really should just have before continuing.
Is this the type of thing that would be worth having a canned or community answer for? Questions might all be slightly dissimilar but a sane answer always is 'learn promises, then come back if you're stuck' (but more politely/encouraging).
async
async
is nice and I'm glad it exists but it's a very leaky abstraction. People will still misuse it and come here confused when their code doesn't work.new Promise
, we have a canonical about thePromise
constructor antipattern (and I use canned comments in every second [promise] question)