18 using System.Threading;
19 using System.Collections;
20 using System.Collections.Generic;
35 private readonly
bool _isBlocking;
36 private long _consumerCount;
37 private Queue<T> _consumer =
new();
38 private Queue<T> _producer =
new();
39 private readonly
object _lock =
new object();
40 private readonly ManualResetEventSlim _resetEvent =
new(
false);
52 return _producer.Count + (int)Interlocked.Read(ref _consumerCount);
71 _isBlocking = blocking;
82 _producer.Enqueue(data);
84 if(!_resetEvent.IsSet)
104 _resetEvent.Dispose();
118 if (_consumer.TryDequeue(out _current))
120 Interlocked.Decrement(ref _consumerCount);
127 var producer = _producer;
132 _producer = _consumer;
134 _consumer = producer;
135 if(_consumer.Count > 0)
137 _current = _consumer.Dequeue();
138 Interlocked.Exchange(ref _consumerCount, _consumer.Count);
152 _resetEvent.Wait(Timeout.Infinite);
155 catch (ObjectDisposedException)
179 throw new NotImplementedException(
"EnqueableEnumerator.Reset() has not been implemented yet.");
190 get {
return _current; }
200 object IEnumerator.Current