4 ms·
JavaScript: Async math is hard
- saurik 8y agoFWIW, 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 8y agoThey 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.
- AntonyGarand 8y agoWell, considering `x = x + await 2` and `x = await 2 + x` produces different behavior, it is more related to async/await than to the `+=` operator!
- marcodave 8y agoam I the only one that would answer that question with "this code is evil and you should feel bad" ?
- AntonyGarand 8y agoThe 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`
- mabynogy 8y agoYeah 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