|
1 |
| -/* Copyright 2016 MongoDB Inc. |
| 1 | +/* Copyright 2016-2017 MongoDB Inc. |
2 | 2 | *
|
3 | 3 | * Licensed under the Apache License, Version 2.0 (the "License");
|
4 | 4 | * you may not use this file except in compliance with the License.
|
@@ -244,27 +244,41 @@ private async Task GetFirstBatchAsync(CancellationToken cancellationToken)
|
244 | 244 |
|
245 | 245 | private void GetNextBatch(CancellationToken cancellationToken)
|
246 | 246 | {
|
247 |
| - var hasMore = _cursor.MoveNext(cancellationToken); |
248 |
| - GetNextBatchFromCursor(hasMore); |
| 247 | + List<BsonDocument> batch; |
| 248 | + do |
| 249 | + { |
| 250 | + var hasMore = _cursor.MoveNext(cancellationToken); |
| 251 | + batch = hasMore ? _cursor.Current.ToList() : null; |
| 252 | + } |
| 253 | + while (batch != null && batch.Count == 0); |
| 254 | + |
| 255 | + ProcessNextBatch(batch); |
249 | 256 | }
|
250 | 257 |
|
251 | 258 | private async Task GetNextBatchAsync(CancellationToken cancellationToken)
|
252 | 259 | {
|
253 |
| - var hasMore = await _cursor.MoveNextAsync(cancellationToken).ConfigureAwait(false); |
254 |
| - GetNextBatchFromCursor(hasMore); |
| 260 | + List<BsonDocument> batch; |
| 261 | + do |
| 262 | + { |
| 263 | + var hasMore = await _cursor.MoveNextAsync(cancellationToken).ConfigureAwait(false); |
| 264 | + batch = hasMore ? _cursor.Current.ToList() : null; |
| 265 | + } |
| 266 | + while (batch != null && batch.Count == 0); |
| 267 | + |
| 268 | + ProcessNextBatch(batch); |
255 | 269 | }
|
256 | 270 |
|
257 |
| - private void GetNextBatchFromCursor(bool hasMore) |
| 271 | + private void ProcessNextBatch(List<BsonDocument> batch) |
258 | 272 | {
|
259 |
| - if (!hasMore) |
| 273 | + if (batch == null) |
260 | 274 | {
|
261 | 275 | #pragma warning disable 618
|
262 | 276 | throw new GridFSChunkException(_idAsBsonValue, _nextChunkNumber, "missing");
|
263 | 277 | #pragma warning restore
|
264 | 278 | }
|
265 | 279 |
|
266 | 280 | var previousBatch = _batch;
|
267 |
| - _batch = _cursor.Current.ToList(); |
| 281 | + _batch = batch; |
268 | 282 |
|
269 | 283 | if (previousBatch != null)
|
270 | 284 | {
|
|
0 commit comments