allow cancelling MoveNext operations

pull/12822/head
Jan Tattermusch 7 years ago
parent 8e2e9a6d91
commit bb872c02d9
  1. 5
      src/csharp/Grpc.Core/IAsyncStreamReader.cs
  2. 6
      src/csharp/Grpc.Core/Internal/ClientResponseStream.cs
  3. 7
      src/csharp/Grpc.Core/Internal/ServerRequestStream.cs

@ -41,6 +41,11 @@ namespace Grpc.Core
/// (<c>MoveNext</c> will return <c>false</c>) and the <c>CancellationToken</c>
/// associated with the call will be cancelled to signal the failure.
/// </para>
/// <para>
/// <c>MoveNext()</c> operations can be cancelled via a cancellation token. Cancelling
/// an individual read operation has the same effect as cancelling the entire call
/// (which will also result in the read operation returning prematurely).
/// </para>
/// </summary>
/// <typeparam name="T">The message type.</typeparam>
public interface IAsyncStreamReader<T> : IAsyncEnumerator<T>

@ -49,10 +49,9 @@ namespace Grpc.Core.Internal
public async Task<bool> MoveNext(CancellationToken token)
{
if (token != CancellationToken.None)
var cancellationTokenRegistration = token.CanBeCanceled ? token.Register(() => call.Cancel()) : (IDisposable) null;
using (cancellationTokenRegistration)
{
throw new InvalidOperationException("Cancellation of individual reads is not supported.");
}
var result = await call.ReadMessageAsync().ConfigureAwait(false);
this.current = result;
@ -63,6 +62,7 @@ namespace Grpc.Core.Internal
}
return true;
}
}
public void Dispose()
{

@ -49,14 +49,15 @@ namespace Grpc.Core.Internal
public async Task<bool> MoveNext(CancellationToken token)
{
if (token != CancellationToken.None)
var cancellationTokenRegistration = token.CanBeCanceled ? token.Register(() => call.Cancel()) : (IDisposable) null;
using (cancellationTokenRegistration)
{
throw new InvalidOperationException("Cancellation of individual reads is not supported.");
}
var result = await call.ReadMessageAsync().ConfigureAwait(false);
this.current = result;
return result != null;
}
}
public void Dispose()
{

Loading…
Cancel
Save