BT

Microsoft Enables Async/Await in Edge Preview Build

by David Iffland on Oct 14, 2015 |

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

Relevance
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
General Feedback
Bugs
Advertising
Editorial
Marketing
InfoQ.com and all content copyright © 2006-2016 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT

We notice you’re using an ad blocker

We understand why you use ad blockers. However to keep InfoQ free we need your support. InfoQ will not provide your data to third parties without individual opt-in consent. We only work with advertisers relevant to our readers. Please consider whitelisting us.