Skip to content

Commit

Permalink
Use builtin methods to ConcurrentDictionary (#2073)
Browse files Browse the repository at this point in the history
Update SimpleClientFactory to use builtin methods to ConcurrentDictionary to avoid adding a key multiple times when run concurrently
  • Loading branch information
sensslen authored Jul 4, 2023
1 parent 8dece74 commit 84db183
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions src/RestSharp/SimpleClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ static class SimpleClientFactory {

public static HttpClient GetClient(Uri baseUrl, Func<HttpClient> getClient) {
var key = baseUrl.ToString();
if (CachedClients.TryGetValue(key, out var client)) return client;
client = getClient();
CachedClients.TryAdd(key, client);
return client;
return CachedClients.GetOrAdd(key, key => getClient());
}
}

0 comments on commit 84db183

Please sign in to comment.