Skip to content

Commit 72b74d6

Browse files
fix(client): allow cancelling when enumerating over an http response
1 parent 887b042 commit 72b74d6

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/Orb/Core/HttpResponse.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.IO;
55
using System.Net;
66
using System.Net.Http;
7+
using System.Runtime.CompilerServices;
78
using System.Text.Json;
89
using System.Threading.Tasks;
910
using Orb.Exceptions;
@@ -161,12 +162,17 @@ internal StreamingHttpResponse(
161162
this.CancellationToken = response.CancellationToken;
162163
}
163164

164-
public IAsyncEnumerable<T> Enumerate(Threading::CancellationToken cancellationToken = default)
165+
public async IAsyncEnumerable<T> Enumerate(
166+
[EnumeratorCancellationAttribute] Threading::CancellationToken cancellationToken = default
167+
)
165168
{
166169
using var cts = Threading::CancellationTokenSource.CreateLinkedTokenSource(
167170
this.CancellationToken,
168171
cancellationToken
169172
);
170-
return this._enumerate(cts.Token);
173+
await foreach (var item in this._enumerate(cts.Token))
174+
{
175+
yield return item;
176+
}
171177
}
172178
}

0 commit comments

Comments
 (0)