Hacker News new | ask | show | jobs
by tcoff91 843 days ago
Async and multithreading are not the same thing. Async is about non-blocking execution between functions.

JavaScript is inherently async because the concept of the event loop is baked into the very language runtime itself.

In Java you can achieve a single threaded async runtime by instantiating a SingleThreadExecutor and having all your application code running as jobs posted to this executor. But because you can opt out of this model or use something like a ThreadPoolExecutor it's harder to bake in an `async` keyword into the language that is as simple as you have in JavaScript.

1 comments

I know they're not the same thing. But first class thread support can make asynchrony harder to implement since it sometimes matters which thread the continuation runs on.

> JavaScript is inherently async because the concept of the event loop is baked into the very language runtime itself.

Ok, I hadn't thought about it this way. Early UI frameworks for java had this property as well. I don't know about the implementation. But there was some kind of message loop running, and you'd register event handlers, and events would get dispatched to your handlers.

You could argue that was the framework, not the language. Maybe I'm wrong, but I think of the message loop as being a property of the execution environment (DOM/node) rather than the language. Maybe that's not a real distinction though.