Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ public async ValueTask<SocketResult> ExecuteAsync(

// if the user cancels this stream, we will send the server a complete request
// so that we no longer receive new result messages.
cancellationToken.Register(completion.TrySendCompleteMessage);
var cancellationRegistration = cancellationToken.Register(completion.TrySendCompleteMessage);

try
{
return new SocketResult(observer, subscription, completion);
return new SocketResult(observer, subscription, completion, cancellationRegistration);
}
catch
{
cancellationRegistration.Dispose();
subscription.Dispose();
observer.Dispose();
throw;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ public sealed class SocketResult : IDisposable
internal SocketResult(
DataMessageObserver observer,
IDisposable subscription,
IDataCompletion completion)
IDataCompletion completion,
CancellationTokenRegistration cancellationRegistration)
{
ArgumentNullException.ThrowIfNull(observer);
ArgumentNullException.ThrowIfNull(subscription);

_enumerable = new ResultEnumerable(observer, subscription, completion);
_enumerable = new ResultEnumerable(observer, subscription, completion, cancellationRegistration);
}

/// <summary>
Expand All @@ -44,7 +45,8 @@ public void Dispose()
private sealed class ResultEnumerable(
DataMessageObserver observer,
IDisposable subscription,
IDataCompletion completion)
IDataCompletion completion,
CancellationTokenRegistration cancellationRegistration)
: IAsyncEnumerable<OperationResult>, IDisposable
{
private bool _started;
Expand Down Expand Up @@ -89,6 +91,7 @@ public async IAsyncEnumerator<OperationResult> GetAsyncEnumerator(
public void Dispose()
{
completion.TrySendCompleteMessage();
cancellationRegistration.Dispose();
subscription.Dispose();
observer.Dispose();
}
Expand Down
Loading