Skip to content

Commit 44d7cc5

Browse files
committed
Add ConfigureAwait(false) to all async calls
1 parent 77b04bd commit 44d7cc5

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

WebPush/WebPushClient.cs

+12-7
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ private static EncryptionResult EncryptPayload(PushSubscription subscription, st
284284
public void SendNotification(PushSubscription subscription, string payload = null,
285285
Dictionary<string, object> options = null)
286286
{
287-
SendNotificationAsync(subscription, payload, options).GetAwaiter().GetResult();
287+
SendNotificationAsync(subscription, payload, options).ConfigureAwait(false).GetAwaiter().GetResult();
288288
}
289289

290290
/// <summary>
@@ -329,9 +329,9 @@ public async Task SendNotificationAsync(PushSubscription subscription, string pa
329329
Dictionary<string, object> options = null, CancellationToken cancellationToken = default)
330330
{
331331
var request = GenerateRequestDetails(subscription, payload, options);
332-
var response = await HttpClient.SendAsync(request, cancellationToken);
332+
var response = await HttpClient.SendAsync(request, cancellationToken).ConfigureAwait(false);
333333

334-
HandleResponse(response, subscription);
334+
await HandleResponse(response, subscription).ConfigureAwait(false);
335335
}
336336

337337
/// <summary>
@@ -346,7 +346,7 @@ public async Task SendNotificationAsync(PushSubscription subscription, string pa
346346
VapidDetails vapidDetails, CancellationToken cancellationToken = default)
347347
{
348348
var options = new Dictionary<string, object> { ["vapidDetails"] = vapidDetails };
349-
await SendNotificationAsync(subscription, payload, options, cancellationToken);
349+
await SendNotificationAsync(subscription, payload, options, cancellationToken).ConfigureAwait(false);
350350
}
351351

352352
/// <summary>
@@ -360,15 +360,15 @@ public async Task SendNotificationAsync(PushSubscription subscription, string pa
360360
public async Task SendNotificationAsync(PushSubscription subscription, string payload, string gcmApiKey, CancellationToken cancellationToken = default)
361361
{
362362
var options = new Dictionary<string, object> { ["gcmAPIKey"] = gcmApiKey };
363-
await SendNotificationAsync(subscription, payload, options, cancellationToken);
363+
await SendNotificationAsync(subscription, payload, options, cancellationToken).ConfigureAwait(false);
364364
}
365365

366366
/// <summary>
367367
/// Handle Web Push responses.
368368
/// </summary>
369369
/// <param name="response"></param>
370370
/// <param name="subscription"></param>
371-
private static void HandleResponse(HttpResponseMessage response, PushSubscription subscription)
371+
private static async Task HandleResponse(HttpResponseMessage response, PushSubscription subscription)
372372
{
373373
// Successful
374374
if (response.IsSuccessStatusCode)
@@ -398,7 +398,12 @@ private static void HandleResponse(HttpResponseMessage response, PushSubscriptio
398398
break;
399399
}
400400

401-
var details = response.Content?.ReadAsStringAsync().GetAwaiter().GetResult();
401+
string details = null;
402+
if (response.Content != null)
403+
{
404+
details = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
405+
}
406+
402407
var message = string.IsNullOrEmpty(details)
403408
? responseCodeMessage
404409
: $"{responseCodeMessage}. Details: {details}";

0 commit comments

Comments
 (0)