Skip to content

Commit

Permalink
edits
Browse files Browse the repository at this point in the history
  • Loading branch information
norareidy committed Dec 26, 2024
1 parent 949557d commit a1666a0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ reassemble any event fragments:

We recommend reassembling change event fragments, as shown in the
preceding example, but this step is optional. You can use the same
logic to watch split events and complete change events.
logic to watch both split and complete change events.

The preceding example uses the ``GetNextChangeStreamEvent()``,
``GetNextChangeStreamEventAsync()``, and ``MergeFragment()``
Expand Down
38 changes: 19 additions & 19 deletions source/includes/code-examples/change-streams/change-streams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,25 +67,25 @@ await cursor.ForEachAsync(change =>

// start-split-event-helpers-sync
// Fetches the next complete change stream event
private static IEnumerable<ChangeStreamDocument<TDocument>> GetNextChangeStreamEvent<TDocument>(
IEnumerator<ChangeStreamDocument<TDocument>> changeStreamEnumerator)
{
while (changeStreamEnumerator.MoveNext())
{
var changeStreamEvent = changeStreamEnumerator.Current;
if (changeStreamEvent.SplitEvent != null)
{
var fragment = changeStreamEvent;
while (fragment.SplitEvent.Fragment < fragment.SplitEvent.Of)
{
changeStreamEnumerator.MoveNext();
fragment = changeStreamEnumerator.Current;
MergeFragment(changeStreamEvent, fragment);
}
}
yield return changeStreamEvent;
}
}
private static IEnumerable<ChangeStreamDocument<TDocument>> GetNextChangeStreamEvent<TDocument>(
IEnumerator<ChangeStreamDocument<TDocument>> changeStreamEnumerator)
{
while (changeStreamEnumerator.MoveNext())
{
var changeStreamEvent = changeStreamEnumerator.Current;
if (changeStreamEvent.SplitEvent != null)
{
var fragment = changeStreamEvent;
while (fragment.SplitEvent.Fragment < fragment.SplitEvent.Of)
{
changeStreamEnumerator.MoveNext();
fragment = changeStreamEnumerator.Current;
MergeFragment(changeStreamEvent, fragment);
}
}
yield return changeStreamEvent;
}
}

// Merges a fragment into the base event
private static void MergeFragment<TDocument>(
Expand Down

0 comments on commit a1666a0

Please sign in to comment.