Hacker News new | past | comments | ask | show | jobs | submit login

I've thought about this a lot in relation to typescript over the years and had various opinions -- For some time I thought it'd be better if there was an implicit `await` on every line and require `void` or some other keyword to break execution like `go` in Golang.

But, eventually I realized the difference in pre-emption between languages -- Go can (now) preempt your code in many places, so locks and thread-safety are very important.

The javascript runtime only preempts at certain places, `await` being one. This means I can know no other code can be running without explicit locks around all critical sections.

Finally understanding the trade-offs, I no longer am as frustrated when recoloring a bunch of functions. Instead, I can appreciate the areas where I'm not required to lock certain operations that I would in other languages.




There is no preemption in Javascript. It is based on cooperative multitasking[1] (your await statements and non-blocking callback) which is the opposite of preemption.

[1]https://en.wikipedia.org/wiki/Cooperative_multitasking#:~:te....


As anyone who has done the old setTimeout(fn, 0) trick in the browser probably knows.


They even created setImmediate(fn) for this purpose


If every line had an implicit await then it is indistinguishable from pre-emption, which I think is the point the person you're replying to is trying to make.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: