Skip to content

Commit

Permalink
fix: Remove NextAsync from FeedEnumerable (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
cynicaljoy authored Nov 11, 2024
1 parent 4146f97 commit c87e260
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 44 deletions.
10 changes: 6 additions & 4 deletions Fauna.Test/Integration.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<FeedPage<StreamingSandbox>> asyncEnumerator = feed.GetAsyncEnumerator();
await asyncEnumerator.MoveNextAsync();

Assert.NotNull(feed.CurrentPage, "should have loaded a page");
Assert.IsNotEmpty(feed.Cursor, "should have a cursor");
Expand All @@ -567,8 +568,8 @@ public async Task CanOpenFeedWithQuery()
lastPage = page;
}

// Get another page, should be empty
await feed.NextAsync();
await using IAsyncEnumerator<FeedPage<StreamingSandbox>> asyncEnumeratorAgain = feed.GetAsyncEnumerator();
await asyncEnumeratorAgain.MoveNextAsync();

Assert.IsEmpty(feed.CurrentPage!.Events, "should not have any events");
if (lastPage != null)
Expand All @@ -587,7 +588,8 @@ public async Task CanOpenFeedWithEventSource()
var feed = await _client.EventFeedAsync<StreamingSandbox>(eventSource);
Assert.IsNotNull(feed);

await feed.NextAsync();
await using IAsyncEnumerator<FeedPage<StreamingSandbox>> asyncEnumerator = feed.GetAsyncEnumerator();
await asyncEnumerator.MoveNextAsync();

Assert.IsNotEmpty(feed.Cursor, "should have a cursor");
Assert.IsEmpty(feed.CurrentPage!.Events, "should not have any events");
Expand Down
20 changes: 0 additions & 20 deletions Fauna/Core/FeedEnumberable.cs → Fauna/Core/FeedEnumerable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,6 @@ internal FeedEnumerable(
_cancel = cancel;
}

/// <summary>
/// Move to the next page of the Event Feed.
/// </summary>
/// <returns></returns>
public async Task<bool> NextAsync()
{
await using var subscribeFeed = _client.SubscribeFeed<T>(
_eventSource,
_client.MappingCtx,
_cancel);

bool result = await subscribeFeed.MoveNextAsync();
if (result)
{
CurrentPage = subscribeFeed.Current;
}

return result;
}

/// <summary>
/// Returns an enumerator that iterates through the Feed.
/// </summary>
Expand Down
21 changes: 1 addition & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,8 @@ var feed = await client.EventFeedAsync<Person>(eventSource, feedOptions);
var feedFromQuery = await client.EventFeedAsync<Person>(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)
Expand All @@ -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).
Expand Down

0 comments on commit c87e260

Please sign in to comment.