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

Add ConfigureAwait calls to async calls that are awaited #3002

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -12,3 +12,7 @@ dotnet_style_qualification_for_method = true

# IDE0003: Remove qualification
dotnet_style_qualification_for_field = true

[src/Stripe.net/**/*.cs]

dotnet_diagnostic.CA2007.severity = error
6 changes: 3 additions & 3 deletions src/Stripe.net/Infrastructure/Public/StripeClient.cs
Original file line number Diff line number Diff line change
@@ -151,7 +151,7 @@ public async Task<T> RequestAsync<T>(
CancellationToken cancellationToken = default)
where T : IStripeEntity
{
return await this.Requestor.RequestAsync<T>(BaseAddress.Api, method, path, options, requestOptions, cancellationToken);
return await this.Requestor.RequestAsync<T>(BaseAddress.Api, method, path, options, requestOptions, cancellationToken).ConfigureAwait(false);
}

/// <inheritdoc/>
@@ -162,7 +162,7 @@ public async Task<Stream> RequestStreamingAsync(
RequestOptions requestOptions,
CancellationToken cancellationToken = default)
{
return await this.Requestor.RequestStreamingAsync(BaseAddress.Api, method, path, options, requestOptions, cancellationToken);
return await this.Requestor.RequestStreamingAsync(BaseAddress.Api, method, path, options, requestOptions, cancellationToken).ConfigureAwait(false);
}

/// <summary>Sends a request to Stripe's API as a synchronous operation.</summary>
@@ -196,7 +196,7 @@ public async Task<StripeResponse> RawRequestAsync(
RawRequestOptions requestOptions = null,
CancellationToken cancellationToken = default)
{
return await this.Requestor.RawRequestAsync(method, path, content, requestOptions, cancellationToken);
return await this.Requestor.RawRequestAsync(method, path, content, requestOptions, cancellationToken).ConfigureAwait(false);
}

/// <summary>
12 changes: 6 additions & 6 deletions src/Stripe.net/Services/_base/Service.cs
Original file line number Diff line number Diff line change
@@ -281,7 +281,7 @@ internal async IAsyncEnumerable<T> V2ListRequestAutoPagingAsync<T>(
url,
options,
requestOptions,
cancellationToken);
cancellationToken).ConfigureAwait(false);

while (true)
{
@@ -315,7 +315,7 @@ internal async IAsyncEnumerable<T> V2ListRequestAutoPagingAsync<T>(
page.NextPageUrl,
new BaseOptions(),
requestOptions,
cancellationToken);
cancellationToken).ConfigureAwait(false);
}
}

@@ -358,7 +358,7 @@ internal async IAsyncEnumerable<T> V1ListRequestAutoPagingAsync<T>(
url,
options,
requestOptions,
cancellationToken);
cancellationToken).ConfigureAwait(false);

options = options ?? new ListOptions();
bool iterateBackward = false;
@@ -417,7 +417,7 @@ internal async IAsyncEnumerable<T> V1ListRequestAutoPagingAsync<T>(
url,
options,
requestOptions,
cancellationToken);
cancellationToken).ConfigureAwait(false);
}
}

@@ -498,7 +498,7 @@ internal async IAsyncEnumerable<T> SearchRequestAutoPagingAsync<T>(
url,
options,
requestOptions,
cancellationToken);
cancellationToken).ConfigureAwait(false);

options = options ?? new SearchOptions();

@@ -532,7 +532,7 @@ internal async IAsyncEnumerable<T> SearchRequestAutoPagingAsync<T>(
url,
options,
requestOptions,
cancellationToken);
cancellationToken).ConfigureAwait(false);
}
}
}

Unchanged files with check annotations Beta

{
}
public static async Task Main(string[] args)

Check warning on line 12 in src/Examples/Program.cs

GitHub Actions / Build and test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 12 in src/Examples/Program.cs

GitHub Actions / Build and test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 12 in src/Examples/Program.cs

GitHub Actions / Build and test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 12 in src/Examples/Program.cs

GitHub Actions / Build and test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
// To create an example, clone NewExample.cs, implement the example
// copy this line and replace the class name with your new class.
using Stripe.V2.Billing;
public class NewExample
{

Check warning on line 10 in src/Examples/NewExample.cs

GitHub Actions / Build and test

Check warning on line 10 in src/Examples/NewExample.cs

GitHub Actions / Build and test

public static async Task Run()

Check warning on line 12 in src/Examples/NewExample.cs

GitHub Actions / Build and test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 12 in src/Examples/NewExample.cs

GitHub Actions / Build and test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 12 in src/Examples/NewExample.cs

GitHub Actions / Build and test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
var apiKey = "{{API_KEY}}";

Check warning on line 14 in src/Examples/NewExample.cs

GitHub Actions / Build and test

The variable 'apiKey' is assigned but its value is never used

Check warning on line 14 in src/Examples/NewExample.cs

GitHub Actions / Build and test

The variable 'apiKey' is assigned but its value is never used

Check warning on line 14 in src/Examples/NewExample.cs

GitHub Actions / Build and test

The variable 'apiKey' is assigned but its value is never used

Check warning on line 14 in src/Examples/NewExample.cs

GitHub Actions / Build and test

The variable 'apiKey' is assigned but its value is never used
try
{
[ApiController]
public class WebhookController : ControllerBase
{
private readonly StripeClient _client;

Check warning on line 15 in src/Examples/V2/StripeWebhookHandler.cs

GitHub Actions / Build and test

Check warning on line 15 in src/Examples/V2/StripeWebhookHandler.cs

GitHub Actions / Build and test

private readonly string _webhookSecret;

Check warning on line 16 in src/Examples/V2/StripeWebhookHandler.cs

GitHub Actions / Build and test

Field '_webhookSecret' should not begin with an underscore (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1309.md)
public WebhookController()

Check warning on line 18 in src/Examples/V2/StripeWebhookHandler.cs

GitHub Actions / Build and test

Non-nullable field '_webhookSecret' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 18 in src/Examples/V2/StripeWebhookHandler.cs

GitHub Actions / Build and test

Non-nullable field '_webhookSecret' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.
{
var apiKey = Environment.GetEnvironmentVariable("STRIPE_API_KEY");
_client = new StripeClient(apiKey);
_webhookSecret = Environment.GetEnvironmentVariable("WEBHOOK_SECRET");

Check warning on line 23 in src/Examples/V2/StripeWebhookHandler.cs

GitHub Actions / Build and test

Possible null reference assignment.

Check warning on line 23 in src/Examples/V2/StripeWebhookHandler.cs

GitHub Actions / Build and test

Possible null reference assignment.
}
[HttpPost]