|
|
|
|
|
by josephg
823 days ago
|
|
Yeah but this problem goes away entirely if you just don’t await within a critical region like that. I’ve been using nodejs for a decade or so now. Nodejs can also suffer from exactly this problem. In all that time, I think I’ve only reached for a JS locking primitive once. |
|
This is incorrect code
Without the lock, `a` can mutate before `b` is done executing which can mess with whether or not `c` is correct. The problem is if you have 2 independent variables that need to be updated in tandem.Where this might show up. Imagine you have 2 elements on the screen, a span which indicates the contents and a div with the contents.
If your code looks like this
You now have incorrect code if 2 concurrent loads happen. It could be the original foo, it could be a second foo. There's no way to correctly determine what the content of `myDiv` is from an end user perspective as it depends entirely on what finished last and when. You don't even know if loading is still happening.