IEnumerable <RawDataHolder> FetchSourceItems() { for (; ;) { if (itemsBeingProcessed.Count >= processingQueueSize) { yield break; } if (inEnumerator.MoveNext()) { var holder = new RawDataHolder() { Data = inEnumerator.Current }; itemsBeingProcessed.Enqueue(holder); yield return(holder); } else { yield return(null); yield break; } } }
IEnumerable <RawDataHolder> FetchSourceItems() { for (; ;) { var holder = new RawDataHolder(); if (Interlocked.Increment(ref itemsBeingProcessed) > processingQueueSize) { Interlocked.Decrement(ref itemsBeingProcessed); yield break; } if (inEnumerator.MoveNext()) { holder.Data = inEnumerator.Current; yield return(holder); } else { yield return(null); yield break; } } }