|Microsoft Rushes To Embrace The Future - Async In Edge|
|Written by Ian Elliot|
|Thursday, 01 October 2015|
Just as you struggle to get to grips with Promises in ECMAScript 2015, Microsoft has rushed ahead to provide async support in the Chakra engine and Edge.
The important part is that Async functions really make async easy to use and while Promises are used to implement Async functions you can more or less ignore them and how it all works.
If you have an existing function which returns a Promise then you can use it in async function and this basically means ignoring the fact it is asynchronous. For example, if myFunc1 returns a Promise you can use it as an Async function:
That's it - nothing more, nothing complicated and almost no hint of asynchronous operation. If you mark a function as async you can use await within in it to call any function that returns a Promise. You don't need a callback and you don't need to define any of the Promise's methods. You can treat it as if your code pauses until the result of the awaited function completes and it returns its results. You can then write code that processes the results following the call just as if the function was synchronous.
There are a lot more details concerning results and error handling but essentially if you just treat the code as synchronous it will all mostly work.
Put simply async and await are the only sane way to do asynchronous programming.
Microsoft introduced async and await in C# and obviously thinks it's a good idea - so much so that the Chakra and Edge teams have jumped the gun and added it to Edge as an experimental feature that you can turn on.
The EdgeDev Blog has lots of detail about how it is implemented, which is interesting, but the important point is that you don't need to know the detail, to make use of it.
The following video also explains the basic ideas:
Until async/await support is a little more widespread you can't really make much use of it, but you can use it to discover how easy it is.
So the future is here, but we can't make use of it much until it is more widely here. Given Edge is leaving IE behind it could be some time before this happens.
To be informed about new articles onI Programmer, install the I Programmer Toolbar, subscribe to the RSS feed, follow us on, Twitter, Facebook, Google+ or Linkedin, or sign up for our weekly newsletter.
or email your comment to: firstname.lastname@example.org
|Last Updated ( Thursday, 01 October 2015 )|