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.

dartlogo

 

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. 

dartbirdlogo

Banner


Gifts For Geeks 2024
22/11/2024

Are you ready for Thanksgiving, when overeating remorse and a surfeit of being thankful causes the unsettling thought that there are only four weeks till the Xmas break? So here is a mix of weird [ ... ]



Data Wrangler Gets Copilot Integration
11/11/2024

Microsoft has announced that Copilot is being integrated into Data Wrangler. The move will give data scientists the ability to use natural language to clean and transform data, and to get help with fi [ ... ]


More News

 

espbook

 

Comments




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

 

 

 

 

 

 

Last Updated ( Monday, 30 March 2015 )