Skip to content

Commit 02c0599

Browse files
authored
Fix MultiMap concurrency issues (#1687)
* Fix MultiMap concurrency issues * Make ConcurrentList internal * Move ConcurrentEnumerator into separate file * Satisfy linter * Use Roslyn.Utilities.ConcurrentSet * Satisfy linter * Remove ConcurrentEnumerator
1 parent f969fbd commit 02c0599

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/PuppeteerSharp/Helpers/MultiMap.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ namespace PuppeteerSharp.Helpers
66
{
77
internal class MultiMap<TKey, TValue>
88
{
9-
private readonly ConcurrentDictionary<TKey, List<TValue>> _map = new ConcurrentDictionary<TKey, List<TValue>>();
9+
private readonly ConcurrentDictionary<TKey, ICollection<TValue>> _map = new ConcurrentDictionary<TKey, ICollection<TValue>>();
1010

1111
internal void Add(TKey key, TValue value)
12-
=> _map.GetOrAdd(key, _ => new List<TValue>()).Add(value);
12+
=> _map.GetOrAdd(key, _ => new ConcurrentSet<TValue>()).Add(value);
1313

14-
internal List<TValue> Get(TKey key)
15-
=> _map.TryGetValue(key, out var set) ? set : new List<TValue>();
14+
internal ICollection<TValue> Get(TKey key)
15+
=> _map.TryGetValue(key, out var set) ? set : new ConcurrentSet<TValue>();
1616

1717
internal bool Has(TKey key, TValue value)
1818
=> _map.TryGetValue(key, out var set) && set.Contains(value);

0 commit comments

Comments
 (0)