|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:
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
As well as async and await there are a few other enhancements:
Dart 1.9: The release you’ve been await-ing for
Dart Changes Course - No Longer To Be Native In Chrome
Dart 1.8 Adds Support for App Engine and enums
Angular Partners With TypeScript
To be informed about new articles on I 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 ( Monday, 30 March 2015 )|