@@ -424,36 +424,40 @@ private async Task<bool> MoveNextBackAsync(CancellationToken cancellationToken)
424
424
private async Task < bool > MoveNextForwardAsync ( CancellationToken cancellationToken )
425
425
{
426
426
CurrentIndex ++ ;
427
- int tries = 0 ;
428
- while ( true )
429
- {
430
- cancellationToken . ThrowIfCancellationRequested ( ) ;
431
- tries ++ ;
432
427
433
- if ( MaximumLimit != - 1 && Count >= MaximumLimit )
428
+ if ( MaximumLimit != - 1 && Count >= MaximumLimit )
429
+ {
430
+ return false ;
431
+ }
432
+
433
+ if ( CurrentIndex == 0 || CurrentIndex >= CurrentPage . Count )
434
+ {
435
+ int tries = 0 ;
436
+ while ( true )
434
437
{
435
- return false ;
436
- }
438
+ cancellationToken . ThrowIfCancellationRequested ( ) ;
439
+ tries ++ ;
437
440
438
- try
439
- {
440
- await FetchNextPageAsync ( ) . ConfigureAwait ( false ) ;
441
- CurrentIndex = 0 ;
442
- }
443
- catch ( Exception ex )
444
- {
445
- // sleep for a while to see if we can recover
446
- await Sleep ( tries , cancellationToken , ex ) . ConfigureAwait ( false ) ;
447
- }
441
+ try
442
+ {
443
+ await FetchNextPageAsync ( ) . ConfigureAwait ( false ) ;
444
+ CurrentIndex = 0 ;
445
+ }
446
+ catch ( Exception ex )
447
+ {
448
+ // sleep for a while to see if we can recover
449
+ await Sleep ( tries , cancellationToken , ex ) . ConfigureAwait ( false ) ;
450
+ }
448
451
449
- // the page is only populated if there are *new* items to yielded from the listing.
450
- if ( CurrentPage . Count > 0 )
451
- {
452
- break ;
453
- }
452
+ // the page is only populated if there are *new* items to yielded from the listing.
453
+ if ( CurrentPage . Count > 0 )
454
+ {
455
+ break ;
456
+ }
454
457
455
- // No listings were returned in the page.
456
- await Sleep ( tries , cancellationToken ) . ConfigureAwait ( false ) ;
458
+ // No listings were returned in the page.
459
+ await Sleep ( tries , cancellationToken ) . ConfigureAwait ( false ) ;
460
+ }
457
461
}
458
462
Count ++ ;
459
463
return true ;
0 commit comments