Skip to content

Commit 98f1e99

Browse files
authored
Merge pull request #41 from open-olive/SIDE-1091
[SIDE-1091] Add support for IAsyncEnumerable
2 parents 9c7fd93 + aec7218 commit 98f1e99

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

ldk/csharp/OliveHelpsLDK/Example/Program.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,10 @@ private void ClipboardStream()
6565
_clipboardStream = _services.Clipboard.Stream();
6666
Task.Run(async () =>
6767
{
68-
while (await _clipboardStream.MoveNext())
68+
await foreach (var clipboardContent in _clipboardStream.ToAsyncEnumerable())
6969
{
7070
try
7171
{
72-
var clipboardContent = _clipboardStream.Current();
7372
Logger.Info($"Received Clipboard Update \"{clipboardContent}\"");
7473
switch (clipboardContent)
7574
{

ldk/csharp/OliveHelpsLDK/OliveHelpsLDK/IStreamingCall.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System;
2+
using System.Collections.Generic;
3+
using System.Threading;
24
using System.Threading.Tasks;
35

46
namespace OliveHelpsLDK
@@ -8,5 +10,7 @@ public interface IStreamingCall<TOutput> : IDisposable
810
TOutput Current();
911

1012
Task<bool> MoveNext();
13+
14+
IAsyncEnumerable<TOutput> ToAsyncEnumerable(CancellationToken cancellationToken = default);
1115
}
1216
}

ldk/csharp/OliveHelpsLDK/OliveHelpsLDK/OliveHelpsLDK.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Google.Protobuf" Version="3.13.0" />
11-
<PackageReference Include="Grpc" Version="2.33.1" />
12-
<PackageReference Include="Grpc.Tools" Version="2.33.1">
10+
<PackageReference Include="Google.Protobuf" Version="3.13.0"/>
11+
<PackageReference Include="Grpc" Version="2.34.0"/>
12+
<PackageReference Include="Grpc.Net.Common" Version="2.34.0"/>
13+
<PackageReference Include="Grpc.Tools" Version="2.34.0">
1314
<PrivateAssets>all</PrivateAssets>
1415
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1516
</PackageReference>

ldk/csharp/OliveHelpsLDK/OliveHelpsLDK/StreamingCall.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
using System;
2+
using System.Collections.Generic;
3+
using System.Runtime.CompilerServices;
4+
using System.Threading;
25
using System.Threading.Tasks;
36
using Grpc.Core;
47

@@ -30,5 +33,14 @@ public Task<bool> MoveNext()
3033
{
3134
return _call.ResponseStream.MoveNext();
3235
}
36+
37+
public async IAsyncEnumerable<TOutput> ToAsyncEnumerable(
38+
[EnumeratorCancellation] CancellationToken cancellationToken = default)
39+
{
40+
await foreach (var output in _call.ResponseStream.ReadAllAsync(cancellationToken).ConfigureAwait(false))
41+
{
42+
yield return _transformer(output);
43+
}
44+
}
3345
}
3446
}

0 commit comments

Comments
 (0)