In terms of async/await, and then/catch. When do you feel is a good time to use either?
For asynchronous operations, I have most often resort to fetch and then/catch. Not a very varied vocabulary.
@jenninat0r
, It might just be a typo, but I think you meant async/await syntax vs. promises which use then/catch syntax to chain operations (with .catch(cb) being used for error handling). Not try/catch.
In the case of async/await, you'd just use normal try/catch syntax around your await calls for error handling.
Both are used to accomplish the same thing, so I'd say which one you use is a matter of preference. Promises are very similar to monads (although technically they don't quite qualify as such), and I suspect that promises were developed to kind of support a functional style of programming (everything stays in the context of a promise). On the other hand, async/await is designed to make the code look like ordinary imperative code, only asynchronous.
I could be wrong, but I would say whichever one is easier for a team to work with is the one they should use.
To me it seems easier to do error handling when using async/await vs then/catch. Most of the times you need an extra try/catch when you're doing then/catch, but when using async/await both sync and async exceptions are caught.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Thanks for your response.
In terms of
async
/await
, andthen
/catch
. When do you feel is a good time to use either?For asynchronous operations, I have most often resort to
fetch
andthen/catch
. Not a very varied vocabulary.@jenninat0r , It might just be a typo, but I think you meant async/await syntax vs. promises which use then/catch syntax to chain operations (with
.catch(cb)
being used for error handling). Not try/catch.In the case of async/await, you'd just use normal try/catch syntax around your
await
calls for error handling.Both are used to accomplish the same thing, so I'd say which one you use is a matter of preference. Promises are very similar to monads (although technically they don't quite qualify as such), and I suspect that promises were developed to kind of support a functional style of programming (everything stays in the context of a promise). On the other hand, async/await is designed to make the code look like ordinary imperative code, only asynchronous.
I could be wrong, but I would say whichever one is easier for a team to work with is the one they should use.
Yes it was a brain fart. Iβm in the βthen/catchβ camp !
To me it seems easier to do error handling when using async/await vs then/catch. Most of the times you need an extra try/catch when you're doing then/catch, but when using async/await both sync and async exceptions are caught.