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(false) to await calls #71

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
48 changes: 24 additions & 24 deletions src/NetCoreForce.Client/ForceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public ForceClient(string instanceUrl, string apiVersion, string accessToken, Ht
private async Task Login(string clientId, string clientSecret, string username, string password, string tokenRequestEndpoint, string apiVersion = null, HttpClient httpClient = null)
{
AuthenticationClient authClient = new AuthenticationClient(apiVersion);
await authClient.UsernamePasswordAsync(clientId, clientSecret, username, password, tokenRequestEndpoint);
await authClient.UsernamePasswordAsync(clientId, clientSecret, username, password, tokenRequestEndpoint).ConfigureAwait(false);

Initialize(authClient.AccessInfo.InstanceUrl, authClient.ApiVersion, authClient.AccessInfo.AccessToken, httpClient, authClient.AccessInfo);
}
Expand Down Expand Up @@ -161,7 +161,7 @@ public async Task<List<T>> Query<T>(string queryString, bool queryAll = false)
queryUri = new Uri(new Uri(InstanceUrl), nextRecordsUrl);
}

QueryResult<T> qr = await client.HttpGetAsync<QueryResult<T>>(queryUri, headers);
QueryResult<T> qr = await client.HttpGetAsync<QueryResult<T>>(queryUri, headers).ConfigureAwait(false);

#if DEBUG
Debug.WriteLine(string.Format("Got query resuts, {0} totalSize, {1} in this batch, final batch: {2}",
Expand Down Expand Up @@ -207,7 +207,7 @@ public async Task<List<T>> Query<T>(string queryString, bool queryAll = false)
/// <returns>result object</returns>
public async Task<T> QuerySingle<T>(string queryString, bool queryAll = false)
{
List<T> results = await Query<T>(queryString, queryAll);
List<T> results = await Query<T>(queryString, queryAll).ConfigureAwait(false);

if (results != null && results.Count > 1)
{
Expand Down Expand Up @@ -253,7 +253,7 @@ public async IAsyncEnumerable<T> QueryAsync<T>(string queryString, bool queryAll

while (hasMoreRecords)
{
var qr = await jsonClient.HttpGetAsync<QueryResult<T>>(nextRecordsUri, headers);
var qr = await jsonClient.HttpGetAsync<QueryResult<T>>(nextRecordsUri, headers).ConfigureAwait(false);

#if DEBUG
Debug.WriteLine($"Got query resuts, {qr.TotalSize} totalSize, {qr.Records.Count} in this batch, final batch: {qr.Done}");
Expand Down Expand Up @@ -299,7 +299,7 @@ public async Task<int> CountQuery(string queryString, bool queryAll = false)

var jsonClient = new JsonClient(AccessToken, SharedHttpClient);
var uri = UriFormatter.Query(InstanceUrl, ApiVersion, queryString);
var qr = await jsonClient.HttpGetAsync<QueryResult<object>>(uri, headers);
var qr = await jsonClient.HttpGetAsync<QueryResult<object>>(uri, headers).ConfigureAwait(false);

return qr.TotalSize;
}
Expand All @@ -319,7 +319,7 @@ public async Task<SearchResult<T>> Search<T>(string searchString)

JsonClient client = new JsonClient(AccessToken, SharedHttpClient);

SearchResult<T> searchResult = await client.HttpGetAsync<SearchResult<T>>(uri, headers);
SearchResult<T> searchResult = await client.HttpGetAsync<SearchResult<T>>(uri, headers).ConfigureAwait(false);

return searchResult;
}
Expand All @@ -344,7 +344,7 @@ public async Task<SearchResult<SObjectGeneric>> Search(string searchString)

JsonClient client = new JsonClient(AccessToken, SharedHttpClient);

SearchResult<SObjectGeneric> searchResult = await client.HttpGetAsync<SearchResult<SObjectGeneric>>(uri, headers);
SearchResult<SObjectGeneric> searchResult = await client.HttpGetAsync<SearchResult<SObjectGeneric>>(uri, headers).ConfigureAwait(false);

return searchResult;
}
Expand All @@ -368,7 +368,7 @@ public async Task<T> GetObjectById<T>(string sObjectTypeName, string objectId, L

JsonClient client = new JsonClient(AccessToken, SharedHttpClient);

return await client.HttpGetAsync<T>(uri, headers);
return await client.HttpGetAsync<T>(uri, headers).ConfigureAwait(false);
}

/// <summary>
Expand Down Expand Up @@ -404,7 +404,7 @@ public async Task<CreateResponse> CreateRecord<T>(

JsonClient client = new JsonClient(AccessToken, SharedHttpClient);

return await client.HttpPostAsync<CreateResponse>(sObject, uri, headers, fieldsToNull: fieldsToNull, ignoreNulls: ignoreNulls);
return await client.HttpPostAsync<CreateResponse>(sObject, uri, headers, fieldsToNull: fieldsToNull, ignoreNulls: ignoreNulls).ConfigureAwait(false);
}

/// <summary>
Expand Down Expand Up @@ -476,7 +476,7 @@ public async Task<SObjectTreeResponse> CreateMultiple(

SObjectTreeRequest treeRequest = new SObjectTreeRequest(sObjects);

return await client.HttpPostAsync<SObjectTreeResponse>(treeRequest, uri, headers, fieldsToNull: fieldsToNull, ignoreNulls: ignoreNulls);
return await client.HttpPostAsync<SObjectTreeResponse>(treeRequest, uri, headers, fieldsToNull: fieldsToNull, ignoreNulls: ignoreNulls).ConfigureAwait(false);
}

/// <summary>
Expand Down Expand Up @@ -515,7 +515,7 @@ public async Task UpdateRecord<T>(

JsonClient client = new JsonClient(AccessToken, SharedHttpClient);

await client.HttpPatchAsync<object>(sObject, uri, headers, ignoreNulls: ignoreNulls, fieldsToNull: fieldsToNull);
await client.HttpPatchAsync<object>(sObject, uri, headers, ignoreNulls: ignoreNulls, fieldsToNull: fieldsToNull).ConfigureAwait(false);

return;
}
Expand Down Expand Up @@ -573,7 +573,7 @@ public async Task<List<UpsertResponse>> UpdateRecords(

UpsertRequest upsertRequest = new UpsertRequest(sObjects, allOrNone);

return await client.HttpPatchAsync<List<UpsertResponse>>(upsertRequest, uri, headers, includeSObjectId: true, fieldsToNull: fieldsToNull, ignoreNulls: ignoreNulls);
return await client.HttpPatchAsync<List<UpsertResponse>>(upsertRequest, uri, headers, includeSObjectId: true, fieldsToNull: fieldsToNull, ignoreNulls: ignoreNulls).ConfigureAwait(false);

}

Expand Down Expand Up @@ -614,7 +614,7 @@ public async Task<UpsertResponse> InsertOrUpdateRecord<T>(

JsonClient client = new JsonClient(AccessToken, SharedHttpClient);

return await client.HttpPatchAsync<UpsertResponse>(sObject, uri, headers, fieldsToNull: fieldsToNull, ignoreNulls: ignoreNulls);
return await client.HttpPatchAsync<UpsertResponse>(sObject, uri, headers, fieldsToNull: fieldsToNull, ignoreNulls: ignoreNulls).ConfigureAwait(false);
}

/// <summary>
Expand All @@ -631,7 +631,7 @@ public async Task DeleteRecord(string sObjectTypeName, string objectId)

JsonClient client = new JsonClient(AccessToken, SharedHttpClient);

await client.HttpDeleteAsync<object>(uri, headers);
await client.HttpDeleteAsync<object>(uri, headers).ConfigureAwait(false);

return;
}
Expand All @@ -656,13 +656,13 @@ public async Task<Stream> BlobRetrieveStream(string blobUrl)
string objectId = match.Groups[2].Value;
string blobField = match.Groups[3].Value;

return await BlobRetrieveStream(sObjectTypeName, objectId, blobField);
return await BlobRetrieveStream(sObjectTypeName, objectId, blobField).ConfigureAwait(false);
}

public async Task<Stream> BlobRetrieveStream(string sObjectTypeName, string objectId, string blobField)
{
HttpResponseMessage response = await BlobRetrieveResponse(sObjectTypeName, objectId, blobField);
return await response.Content.ReadAsStreamAsync();
HttpResponseMessage response = await BlobRetrieveResponse(sObjectTypeName, objectId, blobField).ConfigureAwait(false);
return await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
}

// public async Task<byte[]> BlobRetrieveBytes(string blobUrl)
Expand Down Expand Up @@ -734,7 +734,7 @@ public async Task<OrganizationLimits> GetOrganizationLimits()

JsonClient client = new JsonClient(AccessToken, SharedHttpClient);

return await client.HttpGetAsync<OrganizationLimits>(uri);
return await client.HttpGetAsync<OrganizationLimits>(uri).ConfigureAwait(false);
}

/// <summary>
Expand All @@ -745,7 +745,7 @@ public async Task<OrganizationLimits> GetOrganizationLimits()
/// <returns>List of SalesforceVersion objects</returns>
public async Task<List<SalesforceVersion>> GetAvailableRestApiVersions(string currentInstanceUrl = null)
{
return await GetAvailableRestApiVersions(currentInstanceUrl, true);
return await GetAvailableRestApiVersions(currentInstanceUrl, true).ConfigureAwait(false);
}

private async Task<List<SalesforceVersion>> GetAvailableRestApiVersions(string currentInstanceUrl = null, bool deserializeResponse = true)
Expand All @@ -769,7 +769,7 @@ private async Task<List<SalesforceVersion>> GetAvailableRestApiVersions(string c

JsonClient client = new JsonClient(AccessToken, SharedHttpClient);

return await client.HttpGetAsync<List<SalesforceVersion>>(uri: uri, deserializeResponse: deserializeResponse);
return await client.HttpGetAsync<List<SalesforceVersion>>(uri: uri, deserializeResponse: deserializeResponse).ConfigureAwait(false);
}

/// <summary>
Expand All @@ -782,7 +782,7 @@ public async Task<UserInfo> GetUserInfo(string identityUrl)
{
JsonClient client = new JsonClient(AccessToken, SharedHttpClient);

return await client.HttpGetAsync<UserInfo>(new Uri(identityUrl));
return await client.HttpGetAsync<UserInfo>(new Uri(identityUrl)).ConfigureAwait(false);
}

/// <summary>
Expand All @@ -798,7 +798,7 @@ public async Task<SObjectBasicInfo> GetObjectBasicInfo(string objectTypeName)

JsonClient client = new JsonClient(AccessToken, SharedHttpClient);

return await client.HttpGetAsync<SObjectBasicInfo>(uri, headers);
return await client.HttpGetAsync<SObjectBasicInfo>(uri, headers).ConfigureAwait(false);
}

/// <summary>
Expand All @@ -813,7 +813,7 @@ public async Task<SObjectDescribeFull> GetObjectDescribe(string objectTypeName)

JsonClient client = new JsonClient(AccessToken, SharedHttpClient);

return await client.HttpGetAsync<SObjectDescribeFull>(uri);
return await client.HttpGetAsync<SObjectDescribeFull>(uri).ConfigureAwait(false);
}

/// <summary>
Expand All @@ -827,7 +827,7 @@ public async Task<DescribeGlobal> DescribeGlobal()

JsonClient client = new JsonClient(AccessToken, SharedHttpClient);

return await client.HttpGetAsync<DescribeGlobal>(uri);
return await client.HttpGetAsync<DescribeGlobal>(uri).ConfigureAwait(false);
}

#endregion
Expand Down
10 changes: 5 additions & 5 deletions src/NetCoreForce.Client/JsonClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public JsonClient(string accessToken, HttpClient httpClient = null)
public async Task<T> HttpGetAsync<T>(Uri uri, Dictionary<string, string> customHeaders = null, bool deserializeResponse = true)
{
//TODO: can this handle T = string?
return await HttpAsync<T>(uri, HttpMethod.Get, null, customHeaders, deserializeResponse);
return await HttpAsync<T>(uri, HttpMethod.Get, null, customHeaders, deserializeResponse).ConfigureAwait(false);
}

/// <summary>
Expand Down Expand Up @@ -106,7 +106,7 @@ public async Task<T> HttpPostAsync<T>(
request.Method = HttpMethod.Post;
request.Content = content;

return await GetResponse<T>(request, customHeaders, deserializeResponse);
return await GetResponse<T>(request, customHeaders, deserializeResponse).ConfigureAwait(false);
}

/// <summary>
Expand Down Expand Up @@ -148,7 +148,7 @@ public async Task<T> HttpPatchAsync<T>(

var content = new StringContent(json, Encoding.UTF8, JsonMimeType);

return await HttpAsync<T>(uri, new HttpMethod("PATCH"), content, customHeaders, deserializeResponse);
return await HttpAsync<T>(uri, new HttpMethod("PATCH"), content, customHeaders, deserializeResponse).ConfigureAwait(false);
}

/// <summary>
Expand All @@ -166,7 +166,7 @@ public async Task<T> HttpDeleteAsync<T>(Uri uri, Dictionary<string, string> cust
request.RequestUri = uri;
request.Method = HttpMethod.Delete;

return await GetResponse<T>(request, customHeaders, deserializeResponse);
return await GetResponse<T>(request, customHeaders, deserializeResponse).ConfigureAwait(false);
}

private async Task<T> HttpAsync<T>(Uri uri, HttpMethod httpMethod, HttpContent content = null, Dictionary<string, string> customHeaders = null, bool deserializeResponse = true)
Expand All @@ -180,7 +180,7 @@ private async Task<T> HttpAsync<T>(Uri uri, HttpMethod httpMethod, HttpContent c
request.Content = content;
}

return await GetResponse<T>(request, customHeaders, deserializeResponse);
return await GetResponse<T>(request, customHeaders, deserializeResponse).ConfigureAwait(false);
}

/// <summary>
Expand Down