Remove denepdency on Nito.AsyncEx.Coordination

We don't really need async operations here, ReaderWriterLockSlim is enough
This commit is contained in:
JustArchi
2020-04-10 21:18:45 +02:00
parent d57662811e
commit e05ea63e08
3 changed files with 69 additions and 19 deletions

View File

@@ -22,6 +22,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading;
using JetBrains.Annotations;
namespace ArchiSteamFarm.Collections {
@@ -29,22 +30,24 @@ namespace ArchiSteamFarm.Collections {
public T Current => Enumerator.Current;
private readonly IEnumerator<T> Enumerator;
private readonly IDisposable Lock;
private readonly ReaderWriterLockSlim Lock;
object IEnumerator.Current => Current;
internal ConcurrentEnumerator([NotNull] IReadOnlyCollection<T> collection, [NotNull] IDisposable @lock) {
internal ConcurrentEnumerator([NotNull] IReadOnlyCollection<T> collection, [NotNull] ReaderWriterLockSlim @lock) {
if ((collection == null) || (@lock == null)) {
throw new ArgumentNullException(nameof(collection) + " || " + nameof(@lock));
}
@lock.EnterReadLock();
Lock = @lock;
Enumerator = collection.GetEnumerator();
}
public void Dispose() {
Enumerator.Dispose();
Lock.Dispose();
Lock.ExitReadLock();
}
public bool MoveNext() => Enumerator.MoveNext();