Support for "await" in Dart #104
Comments
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. |
This comment was originally written by miroslav.par...@gmail.com What blocking operation are you referring to? |
cc @gbracha. |
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 :) |
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. |
This comment was originally written by @seaneagan Why does 'await' need to be a keyword? Why not just an 'await()' method in Future/Promise? |
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'. |
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. 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) |
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! |
Added apr30-triage label. |
Removed apr30-triage label. |
Added triage1 label. |
Added Isolates label. |
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. |
Added Library-Isolates label. |
Removed Isolates label. |
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. |
This comment was originally written by jjinux...@google.com Sigmund, should we reassign this ticket to someone else? |
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.
The text was updated successfully, but these errors were encountered: