DEV Community

Discussion on: About async functions

Collapse
 
jcubic profile image
Jakub T. Jankiewicz

I think that your example after "If you make the same function async, it would give you a failed promise." should have async in code. Both examples are the same.

Collapse
 
tkdodo profile image
Dominik D

The next example replaces throw with Promise.reject, both in non-async functions on purpose. The takeaway is that throw is only consistently transformed to failed promises in async functions, which is a detail that is easy to miss. Promise.reject is more explicit and works everywhere.

Collapse
 
jcubic profile image
Jakub T. Jankiewicz

That's right, sorry didn't nice that. I was looking at missing async keyword. Good article.