Skip to content

Commit

Permalink
Use builtin methods to ConcurrentDictionary
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 committed Apr 28, 2023
1 parent 71c73f8 commit 44da863
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 44da863

Please sign in to comment.