Skip to content

Commit 84db183

Browse files
authored
Use builtin methods to ConcurrentDictionary (#2073)
Update SimpleClientFactory to use builtin methods to ConcurrentDictionary to avoid adding a key multiple times when run concurrently
1 parent 8dece74 commit 84db183

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

src/RestSharp/SimpleClientFactory.cs

+1-4
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ static class SimpleClientFactory {
2222

2323
public static HttpClient GetClient(Uri baseUrl, Func<HttpClient> getClient) {
2424
var key = baseUrl.ToString();
25-
if (CachedClients.TryGetValue(key, out var client)) return client;
26-
client = getClient();
27-
CachedClients.TryAdd(key, client);
28-
return client;
25+
return CachedClients.GetOrAdd(key, key => getClient());
2926
}
3027
}

0 commit comments

Comments
 (0)