-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Proposal: An await operator similar to ?. #4714
Comments
Like a an http://stackoverflow.com/questions/12921197/why-does-the-pipe-operator-work http://theburningmonk.com/2011/09/fsharp-pipe-forward-and-pipe-backward |
I'm no f# expert so i'm not quite sure about the exact semantics of the pipe operator, but from my casual understanding, yes (at least partially) :) In my head I map it to the way extensions methods are expanded, so like how |
I'm conflicted about something like this. While I agree that chaining Maybe there could be some middle ground that keeps the |
I like the idea, though it is generally good practice to not chain too many method call together, as it can make debugging more difficult later. I do wonder if this wouldn't open up options for an analyzing, optimizing compiler to make additional optimizations because it could better understand intent...
Yeah, like that. I think I prefer that operator as well. |
I suppose its a matter of preference but i find intermediate variables like that a little distracting :) maybe it's because of the expression bodied member support but i feel like expressions are something we'll use more and more. That said i also sometimes split call chains up for debugging purposes, all though i do that less and less with the improvements to the VS debugger such a pinning I'm not necessarily saying the await operator is bad, in fact i still see it as the best syntax for the "last" await in the call chain, it's just those middle ones that could be prettier. Maybe it doesn't have to be something as innocuous as ">.", having a pipe character in there like in f# would make it more distinct from a regular member access. |
Or hey, how about this:
Where the |
@aL3891 that could become confusing very fast in generic code that returns tasks or observables. |
Agreed. |
yeah, just throwing it out there, some sort of access operator that awaits is probably better |
Actually, as @aluanhaddad said, with help of #5444, and type inference, the example in the original post could be written as string result = await client.GetAsync("http://microsoft.com")
|> await ::Content.ReadAsStringAsync(); |
Ah, neat! |
We are now taking language feature discussion on https://github.com/dotnet/csharplang for C# specific issues, https://github.com/dotnet/vblang for VB-specific features, and https://github.com/dotnet/csharplang for features that affect both languages. See also dotnet/csharplang#35 for a proposal under consideration. |
Hi there,
Alot of times, especially when doing http requests with HttpClient, you have one async operation that is closely tied to another async operation. for example making a webrequest and then downloading the response. This can result on code that looks like this:
However wouldn't it be nice if the language supported doing something like
Note that the >. is just something i pulled out of my hat, but the point is to have a "dot" operator that actually awaits and returns the result. I know i could just make a specific extension method that awaits the first call and then returns the second task like this
but having this in the language and generalized would be neat
What do you think?
The text was updated successfully, but these errors were encountered: