kenhuuu commented on code in PR #3403:
URL: https://github.com/apache/tinkerpop/pull/3403#discussion_r3184733313
##########
gremlin-dotnet/src/Gremlin.Net/Driver/ResultSet.cs:
##########
@@ -21,49 +21,134 @@
#endregion
-using System.Collections;
+using System;
using System.Collections.Generic;
+using System.Threading;
+using System.Threading.Channels;
+using System.Threading.Tasks;
namespace Gremlin.Net.Driver
{
/// <summary>
- /// A ResultSet is returned from the submission of a Gremlin script to
the server and represents the results
- /// provided by the server. ResultSet includes enumerable data and
status attributes.
+ /// A streaming ResultSet returned from the submission of a Gremlin
request.
+ /// Implements <see cref="IAsyncEnumerable{T}"/>; so consumers can
iterate results as they
+ /// arrive from the server via <c>await foreach</c>.
+ /// Single-consumer only — calling GetAsyncEnumerator a second time
throws
+ /// InvalidOperationException.
/// </summary>
/// <typeparam name="T">Type of the result elements</typeparam>
- public sealed class ResultSet<T> : IReadOnlyCollection<T>
+ public sealed class ResultSet<T> : IAsyncEnumerable<T>, IAsyncDisposable,
IDisposable
{
- private readonly IReadOnlyCollection<T> _data;
+ private readonly ChannelReader<object> _channelReader;
+ private readonly CancellationTokenSource _disposeCts;
+ private readonly Task _backgroundTask;
+ private int _enumerated; // 0 = not yet, 1 = already enumerated
Review Comment:
Nit: not immediately obvious that these are ints not booleans due to the use
of InterLocked and restrictions prior to .NET 9.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]