Fauna v10 .NET/C# Driver 0.3.0-beta
 
Loading...
Searching...
No Matches
StreamEnumerable.cs
Go to the documentation of this file.
1using Fauna.Types;
3
4namespace Fauna.Core;
5
6public class StreamEnumerable<T> where T : notnull
7{
8 private readonly BaseClient _client;
9 private readonly Stream _stream;
10 private readonly CancellationToken _cancel;
11
12 public string Token => _stream.Token;
13
14 internal StreamEnumerable(
15 BaseClient client,
16 Stream stream,
17 CancellationToken cancel = default)
18 {
19 _client = client;
20 _stream = stream;
21 _cancel = cancel;
22 }
23
24 public async IAsyncEnumerator<Event<T>> GetAsyncEnumerator()
25 {
26 await using var subscribeStream = _client.SubscribeStream<T>(
27 _stream,
28 _client.MappingCtx,
29 _cancel);
30
31 while (!_cancel.IsCancellationRequested && await subscribeStream.MoveNextAsync())
32 {
33 yield return subscribeStream.Current;
34 }
35 }
36}
The base class for Client and DataContext.
Definition IClient.cs:371
async IAsyncEnumerator< Event< T > > GetAsyncEnumerator()
Represents a Fauna stream token.
Definition Stream.cs:9