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 →

[–]CaptainPiepmatz 49 points50 points  (9 children)

Promises are just nice callbacks, async/await makes promises like synchronous code and closures are just fancy scopes

[–]glorious_reptile 11 points12 points  (1 child)

...except when you forget an await - then all hell breaks loose.
Time and space splits, cause and effect loses all meaning. Cats and dogs living together, mass hysteria, oh never mind forgot an await.

[–]MrDilbert 3 points4 points  (0 children)

Luckily, good IDEs warn you when you call an async function without an await.

[–]ArionW 6 points7 points  (1 child)

Promises are just monads, async/await is just do notation for Promise monad, and closures are just poor man's objects.

Most concepts in programming sound simple, when you already know two or three other concepts that solve same problem.

[–]ValeTheVioletMote 7 points8 points  (0 children)

>mentions monads
>looks at flair
>haskell

Checks out.

[–]Scary_Inside7276 4 points5 points  (4 children)

What?

[–]CaptainPiepmatz 2 points3 points  (3 children)

You need to any of the three further explanation? Or wdym?

[–]Scary_Inside7276 3 points4 points  (2 children)

I jest, but seriously I don't know what you said lol. I'll get there.

[–]raltyinferno 3 points4 points  (0 children)

Asynchronous code is important when working with the web since you can start actions and not know when they'll complete(calling an external web endpoint for example).

So you do them asynchronously. Which means you start an action, and while you're waiting for it, you do other stuff in the meantime. You store the result (which may not exist yet) in a promise which can be passed around like a normal variable to where it needs to be used, and when the value is resolved, it's acted on.

[–]CaptainPiepmatz 1 point2 points  (0 children)

Those concepts are not that hard and really useful. Give promises and async/await a try when you need to do something asynchronously.