From 86f655340573f85854c6c7404d3ab5915f24c073 Mon Sep 17 00:00:00 2001 From: Tim Miller Date: Wed, 5 Mar 2025 15:52:49 +0900 Subject: [PATCH] Check enumerator index (#226) --- .../ATObjectCollectionAsyncEnumerator{T}.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/FishyFlip/ATObjectCollectionAsyncEnumerator{T}.cs b/src/FishyFlip/ATObjectCollectionAsyncEnumerator{T}.cs index 1e2389ee..077b0470 100644 --- a/src/FishyFlip/ATObjectCollectionAsyncEnumerator{T}.cs +++ b/src/FishyFlip/ATObjectCollectionAsyncEnumerator{T}.cs @@ -60,8 +60,16 @@ public async ValueTask MoveNextAsync() if (this.Collection.HasMoreItems) { await this.Collection.GetMoreItemsAsync(cancellationToken: this.cancellationToken); - this.index++; - return true; + + // Need to verify that new items were added with GetMoreItemsAsync to increase the index, + // otherwise it will throw on an out of range index. + if (this.index + 1 < this.Collection.Count) + { + this.index++; + return true; + } + + return this.Collection.HasMoreItems; } return false;