[Proposal] Add an [AutoAwaitAttribute] so compiler will auto-add "await" to async methods #3839
Replies: 9 comments
-
I disagree that making |
Beta Was this translation helpful? Give feedback.
-
Doesn't the extension method need to marked as I can't help but think the simplified function is "so" much easier to read, especially when the asynchronous function names already include an That said, consider the inferred use of Anyway, there may be various technical reasons why this would be complex to implement, but it "feels" like something that could be added. |
Beta Was this translation helpful? Give feedback.
-
No. The extension method needs to be called
The suffix is meaningless. It's the use of
It's not a matter of being complex to implement. The team has been pretty clear that asynchrony is something that the developer should explicitly opt-into and not be something that just kind of happens automagickally. |
Beta Was this translation helpful? Give feedback.
-
Yeah was unaware of the duck-typed The suffix may be meaningless, but it always there in MS functions out of convention - and I think a recommended naming pattern. Your right, it's not required, but still, it's usually there - so again, from a "readability" perspective... Sorry, I'm not familiar with what the team has or hasn't been clear on here, do you know if there's a place I should go to read on these types of opt-in policies? |
Beta Was this translation helpful? Give feedback.
-
The compiler always follows the "awaitable" pattern. It has no special knowledge of |
Beta Was this translation helpful? Give feedback.
-
You don't always want to await on the spot. You sometimes can start tasks and then perform other things while the task is running and only await later on. Such an attribute can affect this situation in unforseen ways. |
Beta Was this translation helpful? Give feedback.
-
Also, don't forget about |
Beta Was this translation helpful? Give feedback.
-
FWIW, this:
Would actually vastly decrease readability for me. I actively prefer an async model where awaiting points are actively visible and understandable in code. Having that be implicit would be a net negative for me. That said, i'm not opposed to other visible approaches that might have better ergonomics than the full |
Beta Was this translation helpful? Give feedback.
-
I don't like this. I usually scan through other's code to make sure that there aren't any non-async long running synchronous code hiding inside an async method. You would be surprised how many people do this. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Suggest a compiler operation that would take
async
/await
heavy code and automatically addawait
where needed to improve code readability when it encounters an attribute likeAutoAwaitAttribute
.For example, the following simplified code:
Would become the following behind the scenes where compiler adds
await
everywhere practical:Beta Was this translation helpful? Give feedback.
All reactions