Skip to content

Commit

Permalink
Merge pull request #102 from coenm/feature/threadsafety
Browse files Browse the repository at this point in the history
Make FakeEnvVars ConcurrentDictionary
  • Loading branch information
rogusdev authored Aug 20, 2024
2 parents 7a37f0d + abf5c3e commit dbf6aba
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/DotNetEnv/Env.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Concurrent;
using System.Linq;
using System.Collections.Generic;
using System.Globalization;
Expand All @@ -10,7 +11,7 @@ public class Env
{
public const string DEFAULT_ENVFILENAME = ".env";

public static Dictionary<string, string> FakeEnvVars = new Dictionary<string, string>();
public static ConcurrentDictionary<string, string> FakeEnvVars = new ConcurrentDictionary<string, string>();

public static IEnumerable<KeyValuePair<string, string>> LoadMulti (string[] paths, LoadOptions options = null)
{
Expand Down
5 changes: 1 addition & 4 deletions src/DotNetEnv/Parsers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ public static KeyValuePair<string, string> SetEnvVar (KeyValuePair<string, strin

public static KeyValuePair<string, string> DoNotSetEnvVar (KeyValuePair<string, string> kvp)
{
if (Env.FakeEnvVars.ContainsKey(kvp.Key)) {
Env.FakeEnvVars.Remove(kvp.Key);
}
Env.FakeEnvVars.Add(kvp.Key, kvp.Value);
Env.FakeEnvVars.AddOrUpdate(kvp.Key, kvp.Value, (_, v) => v);
return kvp;
}

Expand Down

0 comments on commit dbf6aba

Please sign in to comment.