BT

Your opinion matters! Please fill in the InfoQ Survey!

Microsoft Enables Async/Await in Edge Preview Build

| by David Iffland Follow 3 Followers on Oct 14, 2015. Estimated reading time: 1 minute |

A note to our readers: As per your request we have developed a set of features that allow you to reduce the noise, while not losing sight of anything that is important. Get email and web notifications by choosing the topics you are interested in.

Microsoft's Edge browser has enabled the upcoming async/await feature of ES 2016. The feature is still behind an experimental flag in a preview build, but its presence is an important step towards widespread adoption.

JavaScript's inherent asynchronous nature is powerful, but it can also burden developers with excessive code for simple jobs. "Callback hell" is a joke JavaScript developers smile and nod at in dismay. In recent years, developers embraced Promises which enable a better way to deal with async code. Promises have advanced enough to become part of the ES6 spec.

The async/await feature takes Promises a step further, eliminating the need to wire up all the callback pieces required by traditional Promises. In an example where a function getJsonAsync returns a Promise, using async/await allows developers to wire up that same promise in a more synchronous style.

async function getServerData() {
    try {
        // Once the promise is resolved, the value is returned
        var json = await getJsonAsync();
        
    }
    catch (e) {
        // If the promise is rejected, the result ends up in the catch block
    }
}

C# developers may find the syntax familiar; Microsoft introduced async/await for C# 5.0. In C#, the feature allows developers to write asynchronous code in a synchronous manner, without the need to explicitly wire up excessive code. Similarly, async/await in JavaScript is sugar, reducing the need for boilerplate code.

The feature is available in build 10547 as part of the Windows Insider program. The "Enable experimental JavaScript features" flag must be enabled in the about:flags window.

For now, the feature is not available in other browsers. However, the Babel transpiler has support for it as an experimental feature. Support in other browsers is likely not far behind. Mozilla is working on it.

Implementation in browsers is a necessary step in the ECMAScript standards process. Async/await is currently at stage 3, "Candidate". For a proposal to move on to the final stage 4, implementation experience is necessary. The feature's champion, Brian Terlson, spoke about this feature and the TC39 ES2016 process at this year's QCon New York.

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