Skip to content
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

Innermost hasAwaitStarted catch block is a no-op and could be omitted #145

Open
jnm2 opened this issue Aug 15, 2021 · 3 comments
Open

Innermost hasAwaitStarted catch block is a no-op and could be omitted #145

jnm2 opened this issue Aug 15, 2021 · 3 comments

Comments

@jnm2
Copy link
Contributor

jnm2 commented Aug 15, 2021

How can !hasAwaitStarted_a_1_1 in the catch block ever not evaluate to false? It's not assigned anywhere else.

try
{
hasAwaitStarted_a_1_1 = true;
await a_1_1;
}
catch
{
if (!hasAwaitStarted_a_1_1)
{
_ = a_1_1.AsTask().ContinueWith(failedTask => _ = failedTask.Exception, global::System.Threading.Tasks.TaskContinuationOptions.OnlyOnFaulted);
}
throw;
}

@YairHalberstadt
Copy link
Owner

In that particular case you are right. If you want an example where this is relevant check out the testInstancePerDependencyDependenciesWithFactories. In that example async calls are parallelized - so we trigger 2 async calls then await one, then await the other. In that case you can have a situation where you need to keep track of whether an await has started.

We definitely could improve codegen to detect this scenario and remove the unnecessary bookkeeping.

@jnm2
Copy link
Contributor Author

jnm2 commented Aug 15, 2021

Makes sense. I'm not too concerned. Do you want to leave this issue open to track skipping this try block for the innermost await?

@YairHalberstadt
Copy link
Owner

Yep, thanks

@jnm2 jnm2 changed the title Async initialization code looks wrong Innermost hasAwaitStarted catch block is a no-op and could be omitted Aug 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants