BT

New Early adopter or innovator? InfoQ has been working on some new features for you. Learn more

Node 7.6 Brings Default Async/Await Support

| by Sergio De Simone Follow 4 Followers on Feb 27, 2017. Estimated reading time: 1 minute |

Node.js 7.6 has shipped with official support for async/await enabled by default and better performance on low-memory devices.

Async/await support in Node 7.6 comes from updating V8, Chromium’s JavaScript engine, to version 5.5. This means async/await is not considered experimental anymore and can be used without specifying the --harmony flag, which can be used to enable almost-completed features that the V8 team does not consider stable yet.

The main benefit of async/await is avoiding callback hell, which ensues from nesting a sequence of asynchronous operation through their respective callbacks.

This is how, for example, you could handle a sequence of two asynchronous operations using callbacks:

function asyncOperation(callback) {
  asyncStep1(function(response1) {
    asyncStep2(response1, function(response2) {
        callback(...);
    });
  });
}

The use of async/await allows to streamline that code and make it appear as if it were a sequence of synchronous operations:

async function asyncOperation(callback) {
    const response = await asyncStep1();
    return await asyncStep2(response);
}

Another approach to solving callback hell is using Promises, a feature that has been long available in JavaScript. With Promises, the above example would become:

function asyncOperation() {
  return asyncStep1(...)
    .then(asyncStep2(...));
}

Still, using Promises can become cumbersome in more complex situations.

V8 5.5 also introduces several improvements to heap size and zone usage that reduce its memory footprint up to 35% on low-memory devices compared to V8 5.3.

Other notable changes in Node 7.6 are:

  • The old CLI debugger node debug has been rewritten against the new debugger protocol node --inspect, which will be the only one supported in future versions of V8.
  • Support for the file: protocol has been added to fs, so you can write fs.readFile(URL('file:///C:/path/to/file');, (err, data) => {});

In addition to V8 5.5, Node 7.6 also includes other upgraded dependencies, such as cross-platform async I/O library libuv 1.11, and zlib 1.2.11.

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT