r/learnjavascript • • May 01 '20

Async vs. Sync

Post image
413 Upvotes

81 comments sorted by

View all comments

Show parent comments

1

u/[deleted] May 11 '20

No JavaScript is not parallel. Binding it to c is or binding it to whatever the browser gives it is but JavaScript on it's own as a language does not run in parallel. It is concurrent in that it can lob logic into another thread but that's it. Go as a language is parallel and concurrent. It's in the language spec.

The problem with JavaScript's concurrency is that it is all controlled by the os. It itself has not much to do with threading besides letting the child processes spin off.

That's it. So stop calling JavaScript multithreaded and parallel. It can spin threads but that's it. You don't get anything more without 3rd parties, but that's again not JavaScript.

Here's an example of what you could do if it was.

https://divan.dev/posts/go_concurrency_visualize/

1

u/HeinousTugboat May 11 '20

Go as a language is parallel and concurrent. It's in the language spec.

...dude. Go literally does the same thing. It compiles all of your goroutines into threads and lobs them over to the OS too. Go has better semantics for it, yes. But, like.. it's the same thing in the end.

Here's an example of what you could do if it was.

..an example that runs in JavaScript. Go figure.

1

u/[deleted] May 11 '20

It's not even remotely the same thing. First off Goroutines are about 2kbs and they are controlled by the Go scheduler. The scheduler decides if they should be on another thread or cpu. Sure hardware can change this dynamic but how you organize them is based on the logic of your code. Not per thread or cpu. (Which is then obviously controlled by your os. The structuring of the Goroutines stays the same nomatter your hardware. The scheduler knowing when to grow or shrink them is independent of the os. Async in JavaScript just says spin another process while this code runs...... That's it.

With node you are still binding to c and the author says it's not a good idea.

How is that the same thing?

1

u/HeinousTugboat May 11 '20

With node you are still binding to c and the author says it's not a good idea.

I'd like to see which "author" says this as it pertains the core filesystem interop of node.

Stop acting like you're using some third party extension in node. You aren't. Libuv is just as central to node as V8 is.

If you're referring to Dahl's complaints about node, then he's not referring to using native code, he's specifically referring to binding to C as it's unsafe. In Deno he's just using a Rust library instead to fill the same role.