Skip to content

Commit

Permalink
fix: ConfigureAwait(false) all the things because we're targeting net…
Browse files Browse the repository at this point in the history
…standard2.0
  • Loading branch information
Antaris committed Feb 16, 2024
1 parent eedd305 commit 59ed99f
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public async Task<TrybeResponse<OfferingDateAvailability[]>> GetOfferingDates(

var request = new TrybeRequest(HttpMethod.Get, path + "/offering-dates", query);

return await client.FetchAsync<OfferingDateAvailability[]>(request, cancellationToken);
return await client.FetchAsync<OfferingDateAvailability[]>(request, cancellationToken)
.ConfigureAwait(false);
}
}

Expand Down
3 changes: 2 additions & 1 deletion libs/TrybeSDK/Api/Shop/Basket/BasketOperations.Customer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public async Task<TrybeResponse<Basket>> SetCustomerAsync(

var request = new TrybeRequest<Customer>(HttpMethod.Post, path + $"/{basketId}/customer", customer);

return await client.FetchAsync<Customer, Basket>(request, cancellationToken);
return await client.FetchAsync<Customer, Basket>(request, cancellationToken)
.ConfigureAwait(false);
}
}
12 changes: 8 additions & 4 deletions libs/TrybeSDK/Api/Shop/Basket/BasketOperations.Items.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ public async Task<TrybeResponse<Basket>> AddBasketItemAsync(

var request = new TrybeRequest<AddBasketItemRequest>(HttpMethod.Post, path + $"/{basketId}/items", itemRequest);

return await client.FetchAsync<AddBasketItemRequest, Basket>(request, cancellationToken);
return await client.FetchAsync<AddBasketItemRequest, Basket>(request, cancellationToken)
.ConfigureAwait(false);
}

public async Task<TrybeResponse<Basket>> DeleteBasketItemAsync(
Expand All @@ -89,7 +90,8 @@ public async Task<TrybeResponse<Basket>> DeleteBasketItemAsync(

var request = new TrybeRequest(HttpMethod.Delete, path + $"/{basketId}/items/{basketItemId}");

return await client.FetchAsync<Basket>(request, cancellationToken);
return await client.FetchAsync<Basket>(request, cancellationToken)
.ConfigureAwait(false);
}

public async Task<TrybeResponse<Basket>> UpdateBasketItemAsync(
Expand All @@ -104,7 +106,8 @@ public async Task<TrybeResponse<Basket>> UpdateBasketItemAsync(

var request = new TrybeRequest<UpdateBasketItemRequest>(HttpMethod.Put, path + $"/{basketId}/items/{basketItemId}", itemRequest);

return await client.FetchAsync<UpdateBasketItemRequest, Basket>(request, cancellationToken);
return await client.FetchAsync<UpdateBasketItemRequest, Basket>(request, cancellationToken)
.ConfigureAwait(false);
}

public async Task<TrybeResponse<Basket>> UpdateBasketGuestsAsync(
Expand All @@ -117,7 +120,8 @@ public async Task<TrybeResponse<Basket>> UpdateBasketGuestsAsync(

var request = new TrybeRequest<UpdateBasketGuestsRequest>(HttpMethod.Post, path + $"/{basketId}/update-guests", guestsRequest);

return await client.FetchAsync<UpdateBasketGuestsRequest, Basket>(request, cancellationToken);
return await client.FetchAsync<UpdateBasketGuestsRequest, Basket>(request, cancellationToken)
.ConfigureAwait(false);
}
}

Expand Down
6 changes: 4 additions & 2 deletions libs/TrybeSDK/Api/Shop/Basket/BasketOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public async Task<TrybeResponse<Basket>> GetBasketAsync(

var request = new TrybeRequest(HttpMethod.Get, path + $"/{basketId}");

return await client.FetchAsync<Basket>(request, cancellationToken);
return await client.FetchAsync<Basket>(request, cancellationToken)
.ConfigureAwait(false);
}

public async Task<TrybeResponse<Basket>> ReserveBasketAsync(
Expand All @@ -67,6 +68,7 @@ public async Task<TrybeResponse<Basket>> ReserveBasketAsync(

var request = new TrybeRequest(HttpMethod.Post, path + $"/{basketId}/reserve");

return await client.FetchAsync<Basket>(request, cancellationToken);
return await client.FetchAsync<Basket>(request, cancellationToken)
.ConfigureAwait(false);
}
}
3 changes: 2 additions & 1 deletion libs/TrybeSDK/Api/Shop/Offerings/OfferingOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public async Task<TrybeResponse<ShopOffering[]>> GetPartnerOfferingsAsync(

var request = new TrybeRequest(HttpMethod.Get, path, query);

return await client.FetchAsync<ShopOffering[]>(request);
return await client.FetchAsync<ShopOffering[]>(request)
.ConfigureAwait(false);
}
}
3 changes: 2 additions & 1 deletion libs/TrybeSDK/Api/Shop/Orders/OrderOperations.Notes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public async Task<TrybeResponse<OrderNote>> AddNoteAsync(

var request = new TrybeRequest<OrderNote>(HttpMethod.Post, path + $"/{orderId}/notes", note);

return await client.FetchAsync<OrderNote, OrderNote>(request, cancellationToken);
return await client.FetchAsync<OrderNote, OrderNote>(request, cancellationToken)
.ConfigureAwait(false);
}
}
3 changes: 2 additions & 1 deletion libs/TrybeSDK/Api/Shop/Orders/OrderOperations.Payments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public async Task<TrybeResponse<OrderPayment>> AddPaymentAsync(

var request = new TrybeRequest<AddPaymentRequest>(HttpMethod.Post, path + $"/{orderId}/payments", paymentRequest);

return await client.FetchAsync<AddPaymentRequest, OrderPayment>(request, cancellationToken);
return await client.FetchAsync<AddPaymentRequest, OrderPayment>(request, cancellationToken)
.ConfigureAwait(false);
}
}

Expand Down
3 changes: 2 additions & 1 deletion libs/TrybeSDK/Api/Shop/Orders/OrderOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public async Task<TrybeResponse<Order>> SubmitOrderAsync(

var request = new TrybeRequest(HttpMethod.Post, path + $"/{orderId}/submit");

return await client.FetchAsync<Order>(request, cancellationToken);
return await client.FetchAsync<Order>(request, cancellationToken)
.ConfigureAwait(false);
}
}
3 changes: 2 additions & 1 deletion libs/TrybeSDK/Api/Shop/Packages/PackageOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public async Task<TrybeResponse<Package>> GetPackageAsync(

var request = new TrybeRequest(HttpMethod.Get, path + $"/{offeringId}");

return await client.FetchAsync<Package>(request, cancellationToken);
return await client.FetchAsync<Package>(request, cancellationToken)
.ConfigureAwait(false);
}
}
12 changes: 8 additions & 4 deletions libs/TrybeSDK/Api/Sites/SiteOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public async Task<TrybeResponse> DeleteSiteAsync(
Ensure.IsNotNullOrEmpty(siteId, nameof(siteId));
var request = new TrybeRequest(HttpMethod.Delete, path + $"/{siteId}");

return await client.SendAsync(request, cancellationToken);
return await client.SendAsync(request, cancellationToken)
.ConfigureAwait(false);
}

public async Task<TrybeResponse<Site>> GetSiteAsync(
Expand All @@ -90,7 +91,8 @@ public async Task<TrybeResponse<Site>> GetSiteAsync(
Ensure.IsNotNullOrEmpty(siteId, nameof(siteId));
var request = new TrybeRequest(HttpMethod.Get, path + $"/{siteId}");

return await client.FetchAsync<Site>(request, cancellationToken);
return await client.FetchAsync<Site>(request, cancellationToken)
.ConfigureAwait(false);
}

public async Task<TrybeResponse<Site[]>> GetSitesAsync(
Expand All @@ -107,7 +109,8 @@ public async Task<TrybeResponse<Site[]>> GetSitesAsync(

var request = new TrybeRequest(HttpMethod.Get, path, query);

return await client.FetchAsync<Site[]>(request, cancellationToken);
return await client.FetchAsync<Site[]>(request, cancellationToken)
.ConfigureAwait(false);
}

public async Task<TrybeResponse<Site>> UpdateSiteAsync(
Expand All @@ -120,7 +123,8 @@ public async Task<TrybeResponse<Site>> UpdateSiteAsync(

var request = new TrybeRequest<Site>(HttpMethod.Put, path + $"/{siteId}", site);

return await client.FetchAsync<Site>(request, cancellationToken);
return await client.FetchAsync<Site>(request, cancellationToken)
.ConfigureAwait(false);
}
}

56 changes: 38 additions & 18 deletions libs/TrybeSDK/ApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,25 @@ protected internal async Task<TrybeResponse> SendAsync(

try
{
var httpResp = await _http.SendAsync(httpReq, cancellationToken);
var httpResp = await _http.SendAsync(httpReq, cancellationToken)
.ConfigureAwait(false);

var transformedResponse = await TransformResponse(
httpReq.Method,
httpReq.RequestUri,
httpResp);
httpResp)
.ConfigureAwait(false);

if (_settings.CaptureRequestContent && httpReq.Content is not null)
{
transformedResponse.RequestContent = await httpReq.Content.ReadAsStringAsync();
transformedResponse.RequestContent = await httpReq.Content.ReadAsStringAsync()
.ConfigureAwait(false);
}

if (_settings.CaptureResponseContent && httpResp.Content is not null)
{
transformedResponse.ResponseContent = await httpResp.Content.ReadAsStringAsync();
transformedResponse.ResponseContent = await httpResp.Content.ReadAsStringAsync()
.ConfigureAwait(false); ;
}

return transformedResponse;
Expand Down Expand Up @@ -82,16 +86,19 @@ protected internal async Task<TrybeResponse> SendAsync<TRequest>(
var transformedResponse = await TransformResponse(
httpReq.Method,
httpReq.RequestUri,
httpResp);
httpResp)
.ConfigureAwait(false); ;

if (_settings.CaptureRequestContent && httpReq.Content is not null)
{
transformedResponse.RequestContent = await httpReq.Content.ReadAsStringAsync();
transformedResponse.RequestContent = await httpReq.Content.ReadAsStringAsync()
.ConfigureAwait(false);
}

if (_settings.CaptureResponseContent && httpResp.Content is not null)
{
transformedResponse.ResponseContent = await httpResp.Content.ReadAsStringAsync();
transformedResponse.ResponseContent = await httpResp.Content.ReadAsStringAsync()
.ConfigureAwait(false);
}

return transformedResponse;
Expand All @@ -117,21 +124,25 @@ protected internal async Task<TrybeResponse<TResponse>> FetchAsync<TResponse>(

try
{
var httpResp = await _http.SendAsync(httpReq, cancellationToken);
var httpResp = await _http.SendAsync(httpReq, cancellationToken)
.ConfigureAwait(false);

var transformedResponse = await TransformResponse<TResponse>(
httpReq.Method,
httpReq.RequestUri,
httpResp);
httpResp)
.ConfigureAwait(false); ;

if (_settings.CaptureRequestContent && httpReq.Content is not null)
{
transformedResponse.RequestContent = await httpReq.Content.ReadAsStringAsync();
transformedResponse.RequestContent = await httpReq.Content.ReadAsStringAsync()
.ConfigureAwait(false); ;
}

if (_settings.CaptureResponseContent && httpResp.Content is not null)
{
transformedResponse.ResponseContent = await httpResp.Content.ReadAsStringAsync();
transformedResponse.ResponseContent = await httpResp.Content.ReadAsStringAsync()
.ConfigureAwait(false);
}

return transformedResponse;
Expand All @@ -158,21 +169,25 @@ protected internal async Task<TrybeResponse<TResponse>> FetchAsync<TRequest, TRe

try
{
var httpResp = await _http.SendAsync(httpReq, cancellationToken);
var httpResp = await _http.SendAsync(httpReq, cancellationToken)
.ConfigureAwait(false);

var transformedResponse = await TransformResponse<TResponse>(
httpReq.Method,
httpReq.RequestUri,
httpResp);
httpResp)
.ConfigureAwait(false); ;

if (_settings.CaptureRequestContent && httpReq.Content is not null)
{
transformedResponse.RequestContent = await httpReq.Content.ReadAsStringAsync();
transformedResponse.RequestContent = await httpReq.Content.ReadAsStringAsync()
.ConfigureAwait(false);
}

if (_settings.CaptureResponseContent && httpResp.Content is not null)
{
transformedResponse.ResponseContent = await httpResp.Content.ReadAsStringAsync();
transformedResponse.ResponseContent = await httpResp.Content.ReadAsStringAsync()
.ConfigureAwait(false);
}

return transformedResponse;
Expand Down Expand Up @@ -232,7 +247,9 @@ async Task<Error> GetTrybeError()
Error error;
if (response.Content is not null)
{
var result = await response.Content.ReadFromJsonAsync<ErrorContainer>(cancellationToken);
var result = await response.Content.ReadFromJsonAsync<ErrorContainer>(cancellationToken)
.ConfigureAwait(false);

if (result?.Message is not { Length: > 0 })
{
error = new(Resources.ApiClient_UnknownResponse, result?.Errors);
Expand Down Expand Up @@ -285,7 +302,9 @@ async Task<Error> GetTrybeError()
if (response.Content is not null)
{
var result = await response.Content.ReadFromJsonAsync<ErrorContainer>(
_deserializerOptions, cancellationToken);
_deserializerOptions, cancellationToken)
.ConfigureAwait(false);

if (result?.Message is not { Length: > 0 })
{
error = new(Resources.ApiClient_UnknownResponse, result?.Errors);
Expand All @@ -312,7 +331,8 @@ async Task<Error> GetTrybeError()
if (response.Content is not null)
{
data = await response.Content.ReadFromJsonAsync<DataContainer<TResponse>>(
_deserializerOptions, cancellationToken);
_deserializerOptions, cancellationToken)
.ConfigureAwait(false); ;

if (data?.Meta is not null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public async Task<TrybeResponse<BookingFrame>> CreateBookingFrameAsync(
HttpMethod.Post, path + "/create", frameRequest);

return await client.FetchAsync<CreateBookingFrameRequest, BookingFrame>(
request, cancellationToken);
request, cancellationToken)
.ConfigureAwait(false);
}
}

0 comments on commit 59ed99f

Please sign in to comment.