[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Callbacks are completely gone with Node 7 (using --harmony f

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 20
Thread images: 1

Callbacks are completely gone with Node 7 (using --harmony flag)

NodeJS is good now.


var req = require('request-promise');

async function test(url1,url2) {
if(url1 === '' || url2 === '') {
throw new Error();
}
return [await req(url1), await req(url2)];
}

test('http://www.google.com', 'http://www.bing.com')
.then(res=>{
console.log(res);
})
.catch(err=>{
console.log(err);
});
>>
eh go is still faster and fills the same niche. its also designed by smarter people. i think ill stick with go.
>>
Callbacks were never a big deal and nobody ever forced you to inline them.

There are still plenty of cases where you'd want to use callbacks instead of async/await
>>
>>58494304
Why even bother using node if you're going to force shit to be synchronous?
>>
>>58494340
other tasks run while waiting, it only looks synchronous
>>
>>58494304
I haven't touched node in a while but isn't it the whole point? I always thought using async was just a temporary solution until you fix your program model. Granted there were some things that were extremely inconvenient to do without async at least.
>>
>>58494304
Can't you just use await in a try/catch block instead of the .then and .catch callbacks?

try {
res = await test('http://www.google.com', 'http://www.bing.com')
console.log(res);
} catch(err) {
console.log(err);
}


I've only looked briefly into async/await in Javascript but I think that should work.
>>
>>58494728
Yes, but the try-catch needs to be in an async function or you won't have access to the await keyword.
>>
Promises
>>
>>58494321
this
>>58494654
node only looks like true concurrency
>>
why would anyone use node besides hipster points and for the chance to jump on some doomed startup to fix other hipster's shit?
>>
>>58495515
Dont you like learning new techniques / using new technology?
>>
>>58495582
>lots and lots of poop.jpg

why would anyone like learning shit for the sake of it?
>>
>webshits
>programmers
>>
>>58495515
I only use it to prototype APIs and automate frontend builds. Anyone deploying a serious server using it had better have a good excuse.

That said, it's sometimes faster than e.g. Spring + Java because it doesn't need to jump through 100+ call layers of validation, (de)serialization, object mapping, filters and whatever just to grab some JSON from a database and pass it to the client.
>>
>>58495515
One example - for distributed systems that operate on a strict que. Node's event loop basically solves a very complex problem without you even trying.

Node is just a tool, use it for what you will, preferably for what it makes sense.
>>
>>58495515
Best general purpose modern scripting language. For 90% of new non-legacy projects there is little reason to go with anything else.
>>
>>58495602
yah fuck anything new. New stuff is automatically shit.
>>
>>58495515
Why would anyone hate node besides for /g/ points and for the chance to jump on some doomed discussion to shill Haskell?
>>
I'm probably going to stick with Golang for the backend. If I do front end stuff I'll probably try to use as little JS as possible, but if I had to use a framework I'd use react or vue.js.

BUT... can anyone recommend a book on learning the latest nodejs and ECMAscript versions? I quit javascript right when people started using arrow functions.
Thread posts: 20
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.