-
Notifications
You must be signed in to change notification settings - Fork 12
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
AG0019 - Do not await what does not need to be awaited #150
Comments
While the rule itself sounds, I probably wouldn't want this to be enforced as a blocker. You're right that in the quoted case - and in general pass-through cases But the bigger issue in my point of view is for the analyser to decide the cases when it's safe to omit. I guess we can start with very simple cases... But as soon as you do anything else than simple passthrough, you should also public Task<string> GetSomethingAsync(string numericString) => _service.FetchSomethingAsync(Int32.Parse(numericString)); The parsing can throw so you probably want the Also need to keep in mind that it's very easy to forget to add |
I don't think we raised this issue because of statemachine impact, but because it takes away the ability of the caller to decide when to await. Taking away opportunities to parallelize api/database calls. But, I agree that this should be a recommendation and not a blocker. |
@inemtsev Not sure if I get what you mean by
The caller still has control, it can public async Task Main() {
var dbTask = GetDataFromDatabase();
var apiTask = GetDataFromApi();
await Task.WhenAll(dbTask, apiTask);
/* ... */
}
public async Task<int> GetDataFromDatabase => await GetFromDatabaseImplementation(); // Internally awaits for DB
public async Task<int> GetDataFromApi => await GetFromApiImplementation(); // Internally awaits for API Or did I completely miss the point you are trying to make? |
@szaboopeeter Never mind that point, you are correct. I forgot that await does not block in outer context. |
For example in the code below, the
await _service.FetchSomethingAsync()
expression forces compiler to create the state machine that’s behind this feature.It can be easily fixed by
For reference: Link with measurements
The text was updated successfully, but these errors were encountered: