
JavaScript: Async math is hard - AntonyGarand
https://dev.to/antogarand/javascript-async-maths-is-hard-5b6i
======
saurik
FWIW, the thing that was confusing here didn't really have anything to do with
async/await: it was all thanks to +=... which was hilariously also the source
of a major issue recently found in Java 9/10\. I am honestly starting to
become a bit terrified of += :(.

[https://news.ycombinator.com/item?id=17238015](https://news.ycombinator.com/item?id=17238015)

~~~
he0001
They are not equivalent scenarios, which the article explains. The JS one is
about asynchronous isolation context while the java one is just a evaluation
bug.

------
mabynogy
Yeah async is difficult to reason about. I found a solution with generators in
my custom programming language to keep the flow sequential (especially for
UI).

An example of two ok/cancel buttons followed by some sleep (with generators
too):
[http://dailyprog.org/~mabynogy/test/](http://dailyprog.org/~mabynogy/test/)

source code (in my coffescript-like language):
[https://p.sicp.me/irDrC.js](https://p.sicp.me/irDrC.js)

generated output: [https://p.sicp.me/fu6CW.js](https://p.sicp.me/fu6CW.js)

------
marcodave
am I the only one that would answer that question with "this code is evil and
you should feel bad" ?

~~~
AntonyGarand
The fun thing about this is that you're not expecting this code to be bad, I
don't feel like it's wrong to expect the same behavior with and without the
`await`

