From d5a6ddb70e876badd7648086fa72ebcfb7b777d4 Mon Sep 17 00:00:00 2001 From: Darren Cunningham Date: Mon, 11 Nov 2024 13:33:25 -0500 Subject: [PATCH] rely on GetAsyncEnumerator --- Fauna.Test/Integration.Tests.cs | 10 +++++---- .../{FeedEnumberable.cs => FeedEnumerable.cs} | 20 ------------------ README.md | 21 +------------------ 3 files changed, 7 insertions(+), 44 deletions(-) rename Fauna/Core/{FeedEnumberable.cs => FeedEnumerable.cs} (75%) diff --git a/Fauna.Test/Integration.Tests.cs b/Fauna.Test/Integration.Tests.cs index 93910dd1..db89b1ee 100644 --- a/Fauna.Test/Integration.Tests.cs +++ b/Fauna.Test/Integration.Tests.cs @@ -549,7 +549,8 @@ public async Task CanOpenFeedWithQuery() Assert.IsNotEmpty(feed.Cursor, "should have a cursor"); Assert.IsNull(feed.CurrentPage, "should not have loaded a page"); - await feed.NextAsync(); + await using IAsyncEnumerator> asyncEnumerator = feed.GetAsyncEnumerator(); + await asyncEnumerator.MoveNextAsync(); Assert.NotNull(feed.CurrentPage, "should have loaded a page"); Assert.IsNotEmpty(feed.Cursor, "should have a cursor"); @@ -567,8 +568,8 @@ public async Task CanOpenFeedWithQuery() lastPage = page; } - // Get another page, should be empty - await feed.NextAsync(); + await using IAsyncEnumerator> asyncEnumeratorAgain = feed.GetAsyncEnumerator(); + await asyncEnumeratorAgain.MoveNextAsync(); Assert.IsEmpty(feed.CurrentPage!.Events, "should not have any events"); if (lastPage != null) @@ -587,7 +588,8 @@ public async Task CanOpenFeedWithEventSource() var feed = await _client.EventFeedAsync(eventSource); Assert.IsNotNull(feed); - await feed.NextAsync(); + await using IAsyncEnumerator> asyncEnumerator = feed.GetAsyncEnumerator(); + await asyncEnumerator.MoveNextAsync(); Assert.IsNotEmpty(feed.Cursor, "should have a cursor"); Assert.IsEmpty(feed.CurrentPage!.Events, "should not have any events"); diff --git a/Fauna/Core/FeedEnumberable.cs b/Fauna/Core/FeedEnumerable.cs similarity index 75% rename from Fauna/Core/FeedEnumberable.cs rename to Fauna/Core/FeedEnumerable.cs index 741f50a5..1f35bb72 100644 --- a/Fauna/Core/FeedEnumberable.cs +++ b/Fauna/Core/FeedEnumerable.cs @@ -33,26 +33,6 @@ internal FeedEnumerable( _cancel = cancel; } - /// - /// Move to the next page of the Event Feed. - /// - /// - public async Task NextAsync() - { - await using var subscribeFeed = _client.SubscribeFeed( - _eventSource, - _client.MappingCtx, - _cancel); - - bool result = await subscribeFeed.MoveNextAsync(); - if (result) - { - CurrentPage = subscribeFeed.Current; - } - - return result; - } - /// /// Returns an enumerator that iterates through the Feed. /// diff --git a/README.md b/README.md index c51c83de..3c87e754 100644 --- a/README.md +++ b/README.md @@ -319,9 +319,8 @@ var feed = await client.EventFeedAsync(eventSource, feedOptions); var feedFromQuery = await client.EventFeedAsync(FQL($"Person.all().eventsOn({{ .price, .stock }})"), feedOptions); // EventFeedAsync() returns a `FeedEnumerable` instance that can act as an `AsyncEnumerator`. -// Use `foreach()` or `NextAsync()` to iterate through the pages of events. +// Use `foreach()` to iterate through the pages of events. -// Example 1: Use `foreach()` to iterate through feed pages. await foreach (var page in feed) { foreach (var evt in page.Events) @@ -332,24 +331,6 @@ await foreach (var page in feed) } } -// Example 2: Use `NextAsync()` to manually iterate through feed pages. -// `NextAsync()` requests the next page: -await feed.NextAsync(); - -if (feedFromQuery.CurrentPage != null && feedFromQuery.CurrentPage.Events.Any()) -{ - foreach (var evt in feedFromQuery.CurrentPage.Events) - { - Console.WriteLine($"Event Type: {evt.Type}"); - Person person = evt.Data; - Console.WriteLine($"First Name: {person.FirstName} - Last Name: {person.LastName} - Age: {person.Age}"); - } -} - -// Call `NextAsync()` again to fetch the next page: -await feed.NextAsync(); -``` - ## Event Streaming The driver supports [Event Streaming](https://docs.fauna.com/fauna/current/learn/cdc/#event-streaming).