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


OpenAI Library For .NET Exits Beta
19/11/2024

A few months ago the OpenAI .NET library was released as a beta. It has now reached version 2.0.0 and the time has come to leave beta and, with a few amendments enter production readiness.



Google Updates Responsible AI Toolkit
01/11/2024

Google has announced updates to the Responsible Generative AI Toolkit to enable it to be used with any LLM model. The Responsible GenAI Toolkit provides resources to design, build, and evaluate open A [ ... ]


More News

 

espbook

 

Comments




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

 

 

 

 

 

 

Last Updated ( Monday, 30 March 2015 )