Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for "await" in Dart #104

Closed
DartBot opened this issue Oct 13, 2011 · 19 comments

Comments

@DartBot
Copy link

commented Oct 13, 2011

This issue was originally filed by miroslav.parvan...@gmail.com


Can you implement something like C#'s "await" keyword for asynchronous operations? So the example with the isolates would look like this

//using the await
main() {
  var port = await new Printer().spawn();
  for (var message in ['Hello', 'from', 'other', 'isolate']) {
    port.send(message);
  }
  port.send(null);
}

instead of this

//current implementation
main() {
  new Printer().spawn().then((port) {
    for (var message in ['Hello', 'from', 'other', 'isolate']) {
      port.send(message);
    }
    port.send(null);
  });
}

Also this would be very helpful for very complex async scenarios like for example using asynchronous operations in a loop.

@DartBot

This comment has been minimized.

Copy link
Author

commented Oct 13, 2011

This comment was originally written by jat@google.com


At least when compiling to JS, it is not practical to transform the blocking operation into a continuation -- it might be theoretically possible, but it gets really complicated, especially when you have several layers.


Removed Type-Defect label.
Added Type-Enhancement, Area-Language, Triaged labels.

@DartBot

This comment has been minimized.

Copy link
Author

commented Oct 13, 2011

This comment was originally written by miroslav.par...@gmail.com


What blocking operation are you referring to?
In the above "await" does not mean "block until this is done" – it means "yield back to the caller here, and run the rest of the code as a callback when the answer is available"

@dgrove

This comment has been minimized.

Copy link
Member

commented Oct 13, 2011

cc @gbracha.
Set owner to @sigmundch.

@sigmundch

This comment has been minimized.

Copy link
Member

commented Oct 14, 2011

Supporting 'await' is definitively in our radar.

We are actually studying several alternatives for supporting asynchronous work. We'll probably implement a couple prototypes and iterate on the design as we start using the different alternatives. The end result might be very similar to your suggestion, or might be something closer to Earlang, or promise pipelining... we'll see with time :)

@DartBot

This comment has been minimized.

Copy link
Author

commented Nov 2, 2011

This comment was originally written by alexe.kaigorodov@gmail.com


"run the rest of the code as a callback when the answer is available" looks an attractive approach.
It is not that complex - for javascript, it is implemented already:

http://www.neilmix.com/narrativejs/doc/index.html

@DartBot

This comment has been minimized.

Copy link
Author

commented Jan 12, 2012

This comment was originally written by @seaneagan


Why does 'await' need to be a keyword? Why not just an 'await()' method in Future/Promise?

@sigmundch

This comment has been minimized.

Copy link
Member

commented Jan 12, 2012

The new keyword helps the vm/compiler determine when do a continuation passing style (CPS) transformation on the code.

Using a method rather than a keyword is not that easy. In part, there is no plan to support blocking calls in the language, so the same CPS transformation is required if you use a method or a keyword. When using a method, we need to be careful that the vm/compiler performs the CPS translation only when necessary. This should work also when type information is not written. So purely basing the decision on the name of the method being 'await' might be too brittle (e.g. not all methods called 'await' require this).

We are actually still evaluating some alternative syntactic changes we can do instead of adding 'await' as a keyword'.

@DartBot

This comment has been minimized.

Copy link
Author

commented Feb 19, 2012

This comment was originally written by bakerstr...@gmail.com


I think await would be a great way of providing Async operations. Especially when it comes to operations which might break the UI while in operation you could specify the await keyword to call a function which will prevent (or at least help avoid) blocking the UI while in work.

Keywording is also something to consider when talking to extensions as well.
You could have a spec where 'async' methods are handled by browsers (which support it) by putting them in another operation (like Chrome background pages). The async/await keywords could also mark to the compiler that certain optimisations need to be done or left out.

Don't forget that in C# async and await are a pair. Where await marks functions which means "yeild back here!" and async marks functions which the compiler notes as Threaded and marks not to do Optimisations on them which affect Threading.

C# async tokening is also something which would work really well where large Web Applications need to load the Asynchronous operation can provide back progress reports to the page to display something like loading progress to the user.

(Sorry if I have repeated anything, or looked like a fool, I am but a young developer with lots of passion for new things)

@DartBot

This comment has been minimized.

Copy link
Author

commented Apr 22, 2012

This comment was originally written by @bp74


"await" would be really great, it makes the code much more readable. Also a try-catch is much easier. C# done a great job with it!

@anders-sandholm

This comment has been minimized.

Copy link
Contributor

commented Apr 30, 2012

Added apr30-triage label.

@anders-sandholm

This comment has been minimized.

Copy link
Contributor

commented May 1, 2012

Removed apr30-triage label.

@anders-sandholm

This comment has been minimized.

Copy link
Contributor

commented May 1, 2012

Added triage1 label.

@anders-sandholm

This comment has been minimized.

Copy link
Contributor

commented May 2, 2012

Added this to the Later milestone.
Removed triage1 label.

@sigmundch

This comment has been minimized.

Copy link
Member

commented May 14, 2012

Added Isolates label.

@DartBot

This comment has been minimized.

Copy link
Author

commented Aug 24, 2012

This comment was originally written by er...@codesmithtools.com


I believe this feature alone would be a MASSIVE selling point for Dart in the async world of web programming.

@sigmundch

This comment has been minimized.

Copy link
Member

commented Sep 4, 2012

Added Library-Isolates label.

@sigmundch

This comment has been minimized.

Copy link
Member

commented Sep 4, 2012

Removed Isolates label.

@DartBot

This comment has been minimized.

Copy link
Author

commented Dec 29, 2012

This comment was originally written by kel...@home.se


+1 for await. I've been using async/await in C# since the async CTP was released. It really makes the code a LOT more readable than when using callbacks. In the .NET world most new public API:s are now done as Task<T> instead of callbacks which makes await even more useful. Hope to see the Dart libraries move the same way.

@DartBot

This comment has been minimized.

Copy link
Author

commented Dec 30, 2012

This comment was originally written by jjinux...@google.com


Sigmund, should we reassign this ticket to someone else?

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.