Dart 1.9 Now With Async And Await
Written by Ian Elliot   
Monday, 30 March 2015

The latest release of Dart puts its weight behind the async and await approach to implementing asynchronous code. This really is the only sensible way to do the job.



The big problem with asynchronous code is that it makes a mess of the logical flow of your program. Each time something happens that you have to wait for you have to supply a callback and your little bit of logic comes to an end. Promises and Futures help with the problem, but they too distort the flow of control and you still quickly end up with a deeply nested mess. 

The best solution as proposed by C# and now Dart is to introduce two new async and await expressions. They have been implemented in Dart using the existing Future API. Using await/async you can now write asynchronous code in a natual manner. For example:

var database=await connectDb();
var count = await database. queryEmployees().length;

This has the usual look of synchronous flow of control, but the first await suspends the execution of the code and releases the thread to serve events and the rest of the UI. When the asynchronous call is completed the code resumes complete with its state at the next instruction and so on. Notice that you can include asynchronous 

Once you realize how simple and straightforward asynchronous code becomes with the use of async and await you really can't understand why other languages don't introduce them. The good news is that the next version of JavaScript a.k.a ECMAScript 2016 should include async/await. 

As well as async and await there are a few other enhancements: 

  • enum, is now fully supported 

  • The Dart Analyzer has moved to the Dart Analysis Server. This makes it much easier to integrate Dart source analysis into IDE’s beyond the Dart Editor

  • The regular expression engine for the Dart VM is up to 150x faster than the previous implementation

  • The Isolate API has now been fully implemented in the Dart VM, making it much easier to create applications that target multiple CPUs.

Given the recent announcment that Google won't be adding the Dart VM to Chrome, you need to keep in mind that all of these new features are going to be compiled to JavaScript.  

Dart 1.9 will run on IE 9,10 and 11, and the latest versions of Firefox, Chrome and Safari. There is of course serverside Dart, where the problems of having to work with JavaScript vanish. 



Microsoft Reveals Preview C#13 Features

Microsoft has announced details of what will be included in C# 13. The news was announced at Microsoft's recent Build conference. The new version will have enhanced parameters, extension types, and se [ ... ]

Is Rust Safe?

Rust is our great hope for the future. Even if you are not using it you probably have heard of it and believe it is a safer language than C or C++. But is it really?

More News


C book



or email your comment to: comments@i-programmer.info







Last Updated ( Monday, 30 March 2015 )