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

[feature request] Remove GetAwaiter().GetResult() in async context #38

Open
halex2005 opened this issue Aug 2, 2018 · 1 comment
Open

Comments

@halex2005
Copy link

halex2005 commented Aug 2, 2018

Hi! Thanks for great plugin!

Our legacy code has many syncronous operations that can be made asyncronous. For example:

var result = someHttpService.DoOperation();

can be refactored with TAP:

var result = await someHttpService.DoOperationAsync().ConfigureAwait(false);

AsyncConverter does best job here.

But we cannot fully refactor that code to async code automatically for now because of all our methods should be rewritten with async/await.

We decided to refactor with TAP where possible:

string SomeLegacySynchronousCodeThatCannotBeRefactoredToTapForTheMoment()
{
    var result = someHttpService.DoOperationAsync().GetAwaiter().GetResult();
    return result;
}

When containing method SomeLegacySynchronousCodeThatCannotBeRefactoredToTapForTheMoment will be refactored in future with TAP, it is possible to detect method calls GetAwaiter().GetResult() stuff and suggest to change it to await Method().ConfigureAwait(false).

Task<string> SomeRewrittenLegacyAsync()
{
    var result = someHttpService.DoOperationAsync().GetAwaiter().GetResult();
                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                 suggest to remove GetAwaiter().GetResult(), add await instead
    return result;
}

What do you think?
Is it hard to implement?

@GSPP
Copy link

GSPP commented May 29, 2020

Came here to report this. The extension is awesome otherwise.

The codebase I am working on often uses GetAwaiter().GetResult() instead of Result in order to get the nice exception unwrapping behavior.

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