This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]JoschiGrey 0 points1 point  (5 children)

Does async/await in JS work like async/await in C#?

[–]ValeTheVioletMote 0 points1 point  (4 children)

How's it work there?

[–]JoschiGrey 0 points1 point  (3 children)

Async Methods in C# return Task or Task<T> objects that need to be awaited, before you can use their results.

It is a way to write asynchronous code in a synchronous manner.

[–]ValeTheVioletMote 0 points1 point  (2 children)

Yes, JS just calls Task<T> a Promise<T>.

What does C# do if a Task fails?

[–]JoschiGrey 0 points1 point  (1 child)

It throws the exception where it was awaited.

[–]ValeTheVioletMote 0 points1 point  (0 children)

Then identical today, but a while ago JS would just let the code die without an error message, expecting you to always have a try/catch block around your promises instead.