Please Consider to Simplify the Keyword of "await"! #827
Replies: 104 comments 36 replies
-
I think a postfix |
Beta Was this translation helpful? Give feedback.
-
@HaloFour underscore may not be good enough, may be ! should be another option , just like fsharp, but please put it on the right!
|
Beta Was this translation helpful? Give feedback.
-
@juepiezhongren |
Beta Was this translation helpful? Give feedback.
-
@eyalsk just got known that, so get back to underscore |
Beta Was this translation helpful? Give feedback.
-
@juepiezhongren Just a side note, there are some characters or whatever in your post that might make your post unreadable for some people, you may want to edit it. :) |
Beta Was this translation helpful? Give feedback.
-
@eyalsk |
Beta Was this translation helpful? Give feedback.
-
Underscore looks far too difficult to see at a quick glance. Also I like the grammer of await something. something await doesn't make as much sense to me. |
Beta Was this translation helpful? Give feedback.
-
@stuartstein777 please try to consider that u have a function with more than 50 await, with chains, with if, with using, with lock, with everything being muted with await. The codes are really not graceful as C# always should look like. Underscore may not be a good one, but async-programming needs to be as graceful as sync-one. further, simplified is just an option, just like var, just like var out, it makes things easy and elegant but just |
Beta Was this translation helpful? Give feedback.
-
can we add a key word "awaiting ",then translate this: |
Beta Was this translation helpful? Give feedback.
-
@zhangasyncjun property, indexer, function should be equally treated, besides, in this scope, sync functions have to be banned. |
Beta Was this translation helpful? Give feedback.
-
My suggestion is second pair of ().
should be equivalent to
Examples:
|
Beta Was this translation helpful? Give feedback.
-
double() is surely unacceptable, considering a function's result is a delegate |
Beta Was this translation helpful? Give feedback.
-
It shouldn't break anything. In case you are returning delegate (like async Task<Func> AsyncMethod()), you'll just write |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
@cherepets thanks all the same.,u got my point |
Beta Was this translation helpful? Give feedback.
-
Btw, some inlining hint would help for the last suggestion (and would be even better if there was an inline keyword) |
Beta Was this translation helpful? Give feedback.
-
In the meantime I take an idea like @eyalsk as this public static async Task<V> Then<T,V>(this Task<T> obj,Func<T,V> func)
{
return func(await obj);
}
public static async Task<V> Then<T,V>(this Task<T> obj,Func<T,Task<V>> func)
{
return await func(await obj);
}
var taskValue = await task.Then((item) => item.Value); Because I don't know why you use Would you pleased to explain? |
Beta Was this translation helpful? Give feedback.
-
@Thaina Well, because I was providing an example to the OP that posted the following:
which doesn't make use of async/await, I thought to simplify it enough so he/she would understand what's going on and build on that. p.s. Updated my post with the async/await version. |
Beta Was this translation helpful? Give feedback.
-
I'm finding a lot of (await ...).Property now starting to proliferate in my codebases now, especially with ASP.NET Core. i.e. I'm writing a lot of extensions methods for specific Task-Of-T to make the code cleaner
How about using "*" suffix. The compiler can easily work out whether to use * operator or await keyword - Task and Task<T> don't override the * operator.
|
Beta Was this translation helpful? Give feedback.
-
The compiler works in multiple passes - at the point where it needs to decide whether the suffix Moreover, the await operator works with anything that is awaitable - which includes IIRC, if you dig back into the history of the design of async and await they considered using an operator and decided against it. |
Beta Was this translation helpful? Give feedback.
-
Just because a decision was made in the past doesn't mean that it's set in stone... look at how the syntax for anonymous delegates was made better by lambda expressions, or Tuples and deconstructors. I'm not advocating for a complete replacement - that's not possible - just a shortcut to allow us to avoid plastering nested awaits in brackets all over our code base. And, yes, I'm aware the rules regarding the use of the await keyword... but 99.999% of the code that uses await is programming against Task, Task<T>, ValueTask, or ValueTask<T>. I'm pretty sure the compiler team can work out when to use an operator or rewrite to await, after all they managed it for "?" with nullable reference types and Nullable<T> |
Beta Was this translation helpful? Give feedback.
-
I think this is an issue that is asking for improved asynchronous handling? That's how I read it. Seems like everyone is patting themselves on the back for doing such a great job for the .NET asynchronous model. Don't get me wrong, while the current implementation is an improvement over previous models, when other languages mimic you it is not the time to get stale and self-congratulatory. We should continue to innovate and lead the way, right? The sentiment is out there in the wild. Consider: Top-rated vote that was fourth in feature requests, amassing 44 votes, until it was shut down and told to move it to this repository, even though this issue spans way more than the C# language. Nice little discussion that triggered me nicely today, started by @dotMorten:
And from @dotMorten himself:
That entire thread in its own right is also very telling. There seem to be dozens of replies to the question, with each of them having their own take. Anyways, it would be nice to capture this somewhere in a more formal manner, and I would like some assistance in doing so if at all possible. Or is there perhaps a better issue on here that captures this sentiment? I find it interesting that this issue is still open after nearly 3 years despite having so many downvotes. Almost as interesting as shutting down a feature request on a feature request forum and telling us to use GitHub instead. |
Beta Was this translation helpful? Give feedback.
-
@Mike-E-wins Short of having a concrete way of making it better I don't know what else there is to really do here. Most of the issues that pop up appear to be minor syntactic tweaks. Those that are trying to make Nobody is standing back and saying that As for issues that sit for long periods of time, that describes most of the repo. There's an unfortunately wide gulf between issues that are so good that they get LDM attention and championed and issues that are so bad that they're quickly closed, and that backlog limbo is many, many years long. To be fair there's way too many good-enough ideas out there and even out of the issues that the LDM is actively pursuing they probably have more than a decade of work. I'm not sure that there's much more that can be done short of having more community involvement in terms of forking and prototyping ideas out to demonstrate their feasibility and value. That'll never be a guarantee of acceptance, but might lower that bar. That's my opinion, anyway. |
Beta Was this translation helpful? Give feedback.
-
Yeah that is why I was bummed about having the vote dismissed and told to submit it here. You basically summarized my own understanding of what to expect by posting something here. The problem is that I am not an asynchronous wizard/expert and am in no capacity equipped to provide any sort of design/specifications that could be legitimately used. However, I am an end-user of the product, and combined with a lot of other end-users of the product, we're all pointing to pretty much the same pain points. I guess it's a matter of simply being aware of it until there's a legitimate push to make a vNext (if there is one). In the meantime, I continue to be open to feedback for any other next steps that arise here. I am not exactly wanting to open a new issue until I have a sponsor of some sort that could help guide me through. I will also try to work on not getting so triggered on Twitter every time I see the word "async." 😆 |
Beta Was this translation helpful? Give feedback.
-
Ok :) But what is a good solution whose benefits outweigh its own cons? There hasn't been progress here because the domain is complex and challenging, and there's no clear ways that have been proposed to truly make things better.
Consider that asynchrony is inherently complex (same as concurrency, same as locking, etc. etc.). There isn't some magic bullet to change that. There are just tools that can be provided to help people wrangle it a bit better than before. THere were several quotes from dotMorten listed and i agree with them all. For example:
Yes. And also because asynchrony is hard. MS, and the LDM, woudl love it if computers advanced to the poitn where you didn't have to think about it. But the reverse happened. Asynchrony became hugely important, which necessitated developers having to build up their skills in this complex space.
Correct. And it wasn't meant to. Async/await is about asynchrony. Multithreading is about concurrency. Fortunately, these things can work together. For example, i can easily get massive speedup, with good program behavior by utilizing TPL, the threadpool, and using tasks+async/await to wrangle all that. Is it trivial? Definitely not. But these are extremely complex areas. And even making that extreme complexity "medium" complexity instead of "easy" complexity is a great step. |
Beta Was this translation helpful? Give feedback.
-
Just for an interesting exercise in comparative design, Java has decided to take a different tack to trying to solve asynchrony. They plan on adding a form of "virtual thread" which is basically a green-thread and blurring the distinction of whether you're running on them vs. OS threads. http://cr.openjdk.java.net/~rpressler/loom/loom/sol1_part1.html They even call out the approach of using coroutines by C# and Kotlin as leading to the two "colored functions" world. It's an interesting approach and I'm curious as to whether or not they'll be successful. They'll need to update a lot of the JRE to correctly handle blocking when running on a virtual thread so to not block the OS thread, and there's always the threat that third-party code and native code will cause blocking. Blocking an OS thread could block all or a large percentage of the virtual threads. They also appear to be adding continuations to the JVM which should make it simple to build coroutine primitives. |
Beta Was this translation helpful? Give feedback.
-
Thank you @CyrusNajmabadi and @HaloFour. I guess having some reassurance that there is awareness around this issue is what I am after here, and you have provided it. 👍 Honestly, I feel sheepish here because a mere month ago I promised myself to never EVER post anything ever again around this topic again (after the vote on developercommunity was closed -- seriously, that sucked!) but here we are. 😆😞 But in any case, thank you for your feedback and for taking the time to provide your thoughts around the matter. I continue to be open to suggestions on how to proceed, or if that is even possible. I am not looking for anything for "right now," but perhaps in the future if/when inspiration strikes. If you do think of something, please consider this thread and let me others know. I know I can try giving my thoughts/feedback as well and providing any support if I can assemble it accordingly. |
Beta Was this translation helpful? Give feedback.
-
Prompted by this discussion: https://twitter.com/cezary_piatek/status/1356149993124614144 What about something like this:
Where To account for
Or if you have multiple calls, you can override with explicit control:
Taken further, an assembly-level attribute can be applied for default await configuration:
Then:
Or:
|
Beta Was this translation helpful? Give feedback.
-
I think that this is a very difficult problem to solve correctly due to the way that My suggestion would be to add one feature that would make That way, public static async-to-sync-like void A(this System.Threading.Tasks.Task task)
=> await task.ConfigureAwait(false);
public static async-to-sync-like T A<T>(this System.Threading.Tasks.Task<T> task)
=> await task.ConfigureAwait(false); I used Then: var str = await (await (await 5.AAsync().ConfigureAwait(false)).BAsync().ConfigureAwait(false)).CAsync().ConfigureAwait(false); Becomes: var str = name.AAsync().A().BAsync().A().CAsync().A(); With this approach, we retain all the flexibility of the async model: It will work with Task and ValueTask. It handles ConfigureAwait() and developers can choose when to use. The main concern that I have is that we lose the visual hint that we are making async calls. So, a developer reading an unfamiliar code will not know what A() does... Edit: Wow, I just realized that I wrote something similar three years ago :) |
Beta Was this translation helpful? Give feedback.
-
Why is there always a lot of discussion on having shorter or different keywords/syntax for something that works properly but when done wrong can really go bad. Took years for people to properly understand and do right async/await, asynchronous, multi-threading, the differences and how they work (together)... And there are still to this day .NET meetings/conventions with these topis coming up with a lot of new and old developers attending,.. And still things go wrong from time to time resulting in a lot of time spend fixing issues or making workarounds because of a library not doing things proper. Yes, when making a lot (mainly) libraries/UI apps you need to apply I really find that the async/await keywords are really friendly to help make code understandable and helps to explain what is going on to people, especially to some more inexperienced developers or those less associated to the language. I know a lot of developers find that a moot thing, but by gods it is handy to have language features that are not only to be understood by developers. The hint/warning keyword that something happens differently from the standard way of working, is a real big handy thing. And yes more code is become async/await fully as it works a bit like a zombie virus, but until C# and .NET are purely asynchronous from top to bottom then it is really good to have that syntax that is clear on what is going on. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Async is now everywhere, but "await" is always not that convenient, I think 2 things are making trouble:
- 1. await is a bit LONG, especially when a lot of async functions are consequently called, and not forget async using and async stream in C# 8, in which "await" is making cumbersome;
- 2. await is on the LEFT! Considerring how many javaers envy the Extending Method, which is the same troubling when you going to do chaining async function calls with so many "()".
First Proposition: underline to simplify "await":
Thanks to @HaloFour , as underline could be use as variable and member names, it is invalid in regard to properties' await behavior, so it is Not Perfect.
Athough it looks pretty good, but thanks to @eyalsk, "damnit" operator is going to be used for the non-nullable reference types, so............
thanks to @birbilis , this seems to be a good solution, esp when dot is easy to use than most other punctuation marks.
thanks to @gwhzh21, this is best at match the pair.
thanks to @birbilis @HaloFour ,pipe is sure a solution but, but we shall never forget the keyword of "delegate" and "=>", less always made things more gracefull.
thanks to @yaakov-h @eyalsk, extension could make async chain happen. But i have doubts about its performance, considering more Task wraps compared with a struct stateMachine .Besides, there is not a interface which Task and ValueTask both implement and could result in Roslyn creating stateMachine code, because GetAwaiter COMES FROM NO INTERFACE! Extenstion code is not a general solution for all promise-like class and structs.
Beta Was this translation helpful? Give feedback.
All reactions