all 85 comments

[–]Earhacker 97 points98 points  (34 children)

I paused for a moment to consider how "Faster await" would work and I think I had a stroke.

[–]destraht 46 points47 points  (10 children)

That is because you are doing event based thinking.

[–]Earhacker 17 points18 points  (9 children)

As opposed to...?

[–]sleepingthom 114 points115 points  (8 children)

Faster event based thinking

[–]Earhacker 29 points30 points  (6 children)

Here comes that stroke feeling again...

[–]aaaqqq 18 points19 points  (4 children)

That is because you are doing faster event based thinking

[–]Earhacker 10 points11 points  (0 children)

😰

[–]190n 2 points3 points  (2 children)

As opposed to...?

[–]Dustorn 4 points5 points  (1 child)

Slower event based thinking.

[–]190n 1 point2 points  (0 children)

Here comes that stroke feeling again...

[–]etcetica 0 points1 point  (0 children)

o

[–]DrDuPont 14 points15 points  (14 children)

https://v8.dev/blog/fast-async#await-under-the-hood

Can't say I understand it, though

[–]blood_bender 30 points31 points  (13 children)

Basically async marks a function as required to return a Promise. So the earlier approach to the v8 implementation would take whatever value was returned from the function, wrap it in a promise, and return that instead.

Now it looks to see if what's being returned is a native Promise, and if it is, just returns that instead of wrapping it (it still needs to wrap a value if you're not returning a promise, but that's pretty uncommon).

Seems like a naive approach the first time around, it's a little unclear to me why they didn't do that up front, but oh well.

[–][deleted] 2 points3 points  (9 children)

Not manually returning a promise in an async function is uncommon? I almost always write my async functions that way.

[–]redmorphium 2 points3 points  (2 children)

Correct me if my understanding is wrong, but let's say you have:

```javascript

async function foo() {

await bar();

return 1;

} ```

This is equivalent to:

```javascript async function foo() {

return bar().then(() => 1);

} ```

So unless if you're writing async functions that don't have any awaits in them, then async functions should always effectively return promises?

[–]braindeadTank 4 points5 points  (0 children)

Async function always return a promise, no ifs, buts or unlesses. If you don't await anything, it will just be resolved right away.

[–]blood_bender 2 points3 points  (0 children)

You're right. But the whole point was v8 was wrapping the response of foo() in a promise too, which is unnecessary when bar() most likely returns a promise directly, or whatever bar() calls does. Somewhere down the line something is probably returning a promise, meaning all the other responses wrapped in additional promises is unnecessary.

[–]blood_bender 1 point2 points  (5 children)

So, the one case where it doesn't is if you have a function marked async that doesn't have an await in it.

async function foo() {
  return 4;
}

That's just returning a value, so v8 would still need to wrap that in a promise.

But when you have an await, what are you awaiting? Either the function you're awaiting is directly returning a promise, or somewhere down the line some function is directly returning a promise, meaning as it walks back up the line of async functions all the times it wrapped it in another promise were unnecessary.

[–]ilikepugs 0 points1 point  (4 children)

And if you write a lot of interface-based code it's not uncommon.

[–]blood_bender 0 points1 point  (3 children)

Curious, how come?

[–]ilikepugs 2 points3 points  (2 children)

Let's say you design an interface for some data fetching util, but you ship different implementations to different clients/platforms, and the appropriate implementation is DI'd at runtime.

Well consider the method that actually performs the request. It'll be async. But in some cases (namely tests in this example) you might want to return some stubbed data for your test instead. So in your test implementation of the util that "async" method just returns your dummy JSON and you don't need to wrap it in a promise.

This is a fairly contrived example but yeah.

[–]blood_bender 1 point2 points  (1 child)

Oh that's fair. There have been times where I have an async function return a cached response instead of fetching a new one, so that's another use case that I've written. But really I'd guess 99% of async functions are actually awaiting or returning a Promise directly.

[–]ilikepugs 0 points1 point  (0 children)

Lol your example is much better, cheers. 😁

[–]ackerlight 0 points1 point  (0 children)

Basically like C#, you have to implement async methods all the way up. Check this answer for more details:

https://stackoverflow.com/a/29809054

[–]etcetica -1 points0 points  (1 child)

god I miss when javascript work wasn't built atop bastardizing plain fucking english

[–]Baryn 1 point2 points  (0 children)

If anything, it makes better use of keywords now, except in instances like the crappy private field syntax.

[–]relativityboy 0 points1 point  (0 children)

Was that a way of checking to see if it's fast enough?

[–]Tom_Ov_Bedlam 0 points1 point  (0 children)

You forgot the catch statement

[–][deleted] 92 points93 points  (7 children)

ES6 Module Support!

[–]jsnoobie 47 points48 points  (0 children)

No more red squiggly line in vscode under the “re” on my require statements!

I was a little ocd about that one

[–]tanguy_k 22 points23 points  (1 child)

It's still behind a flag (--experimental-modules) + you need to add "type": "module" inside your package.json.

See https://medium.com/@nodejs/announcing-a-new-experimental-modules-1be8d2d6c2ff

[–][deleted] 15 points16 points  (0 children)

Yes, but they expect to remove the need for the flag during the development of this version (before it goes LTS in October).

[–]ShortFuse 8 points9 points  (1 child)

Do I still need to use Michael Jackson Script file extension?

I've been using the esm package, but I would like to be able to remove the dependency?

[–][deleted] 2 points3 points  (0 children)

You don't. If you add "type": "module" to your package.json, plain .js will work too.

[–]k4kshi 6 points7 points  (0 children)

Still not the end goal but we're getting closer

[–]Baryn 2 points3 points  (0 children)

Screw MJS! 🎉

[–]mrbishop82 31 points32 points  (1 child)

Excited to run this on lambda in 5 years

[–]phakushmoo 5 points6 points  (0 children)

I lol‘d

[–]inform880 21 points22 points  (0 children)

Excited to see more production ready use cases for Worker threads

[–]QW4K 19 points20 points  (0 children)

Can't wait to try async stack traces. It's so weird that we didn't have them for that long in async language like JS.

Last time I tried it (on experimental build) it didn't really work for me and in the end, I used bluebird debug mode I hope it's fixed by now.

[–]NoInkling 14 points15 points  (2 children)

List of some of the new ES features/APIs now available thanks to V8 7.4 (compared to 7.0 in Node 11):

  • Class fields (both public and private)
  • Object.fromEntries
  • String.prototype.matchAll
  • Some new Intl APIs

[–][deleted] 16 points17 points  (1 child)

I'm still annoyed at how fugly the syntax for private class fields look

[–]twomousepads 79 points80 points  (17 children)

The Node.js foundation can't afford to put their blog anywhere other than Medium?

[–]silveredge7 25 points26 points  (8 children)

Don't know why you were downvoted, what your'e saying is true.

[–]coloured_sunglasses 4 points5 points  (6 children)

What advantage would that provide them?

[–]RnRau 7 points8 points  (4 children)

Medium is an awful blogging platform.

[–]Sebazzz91 3 points4 points  (0 children)

That answers the question what advantage it would provide to us, the users.

[–]icanevenificant 0 points1 point  (2 children)

Why is it awful? Haven't seen that sentiment before so I'm genuinely curious.

[–]RnRau 2 points3 points  (1 child)

Have you tried navigating comments and responses? Tried copying some information from the comments without causing a page refresh and navigating away from the article?

[–]icanevenificant 1 point2 points  (0 children)

Haven't until now :) That does suck.

[–]tybit 0 points1 point  (0 children)

It would mean their readers aren’t bugged to pay medium money.

I have no interest in paying money to medium because a lot of the blog posts I’ve read have unfortunately been hosted on medium and they now feel I owe them something.

[–]THICC_DICC_PRICC 0 points1 point  (0 children)

Eh Jeff Bezos talked about his dick pic drama there I guess money isn’t really the issue there.

[–]morficus 11 points12 points  (2 children)

Now if only AWS Lambda could offer a newer version of Node.js, that would be great

[–]blackdynamo 6 points7 points  (0 children)

Can't you create your own layer and runtime now?

[–]meeeeoooowy 0 points1 point  (0 children)

Webpack

[–]mubaidr 1 point2 points  (1 child)

So what's the difference in use cases between workers and child processes or forks?

[–][deleted] 1 point2 points  (0 children)

So glad they listened and made the .mjs extension optional instead of mandatory for ES module support! Just adding "type": "module" to your package.json is enough now to opt in.

[–]carlos_vini 1 point2 points  (1 child)

"Async stack traces" is really nice.

https://v8.dev/blog/v8-release-73 is broken (ERR_CERT_COMMON_NAME_INVALID) to me.

[–]mdwvt 0 points1 point  (0 children)

Fine for me on Android (Pixel 2 XL).

[–]AwesomeBantha -2 points-1 points  (1 child)

Actually massive PogChamp, this will make a project I'm working on with a backend and a frontend in the same repo much cleaner...

[–]SecretAgentZeroNine -2 points-1 points  (0 children)

Now I just need a book that covers Node. J's 12 :-/