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 += :(.
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.
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`
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).
6 comments
[ 4.5 ms ] story [ 26.3 ms ] threadhttps://news.ycombinator.com/item?id=17238015
An example of two ok/cancel buttons followed by some sleep (with generators too): http://dailyprog.org/~mabynogy/test/
source code (in my coffescript-like language): https://p.sicp.me/irDrC.js
generated output: https://p.sicp.me/fu6CW.js