|
|
|
|
|
by ralusek
3545 days ago
|
|
This image is absolutely ridiculous. Problem: JavaScript won't run outside browser.
Solution: V8 (V8 was built for Chrome, btw, NodeJS is what took V8 outside of the browser)
Problem: JavaScript is single threaded by design. (This isn't a problem, you even said BY DESIGN)
Solution: Asynchronous programming. (This is a solution that literally allowed applications running on 20-30 machines to drop to 2 machines and still see over an order of magnitude performance improvements).
Problem: Callback hell. (Callback hell is NOT the way any reasonable Node developer programs. Promises are completely sensible to reason through).
Solution: Compile to better language (Promises are native)
I don't know how many times I have to post this, but this is what good Node code looks like. function doComplexAsyncTask() {
return Promise.join(
doParallelAsyncTask1(),
doParallelAsyncTask2(),
doParallelAsyncTask3()
)
.spread((result1, result2, result3) => {
let combo = doSomething(result1, result2, result3);
return saveComboToDBAsync(combo);
})
.then(result => doSomethingElseAsync(result))
.catch(err => handleError(err));
}
And that's an overly complicated example. And then from anywhere else in the code you can call doComplexAsyncTask()
.then(result => doSomethingWithResultAsync(result));
There is no callback hell. The error handling is trivial. Doing parallel tasks is trivial. And that "single threaded" issue is not an issue. The moment parallel tasks1, 2, and 3 START, your application is already serving the next request. There is 100% CPU availability for every single thread, not a single moment is wasted blocking. And if you're running on a multi-core machine, you use node clustering to get 100% CPU usage of all of the cores.People do just regurgitate the same nonsense over and over. |
|