private bool TryGetDocumentsFromQueue(Etag nextDocEtag, ref List<JsonDocument> items)
{
JsonDocument result;
nextDocEtag = HandleEtagGapsIfNeeded(nextDocEtag);
bool hasDocs = false;
while (items.Count < autoTuner.NumberOfItemsToIndexInSingleBatch && prefetchingQueue.TryPeek(out result) && nextDocEtag.CompareTo(result.Etag) >= 0)
{
// safe to do peek then dequeue because we are the only one doing the dequeues
// and here we are single threaded
prefetchingQueue.TryDequeue(out result);
if (result.Etag != nextDocEtag)
continue;
items.Add(result);
hasDocs = true;
nextDocEtag = EtagUtil.Increment(nextDocEtag, 1);
nextDocEtag = HandleEtagGapsIfNeeded(nextDocEtag);
}
return hasDocs;
}