[C#] Add cancellation token overloads to streaming interfaces (#27886)

* Add cancellation token overloads to streaming interfaces

* PR feedback
pull/29010/head
James Newton-King 3 years ago committed by GitHub
parent f574f70c68
commit 5ba6beff18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/csharp/Grpc.Core.Api/Grpc.Core.Api.csproj
  2. 21
      src/csharp/Grpc.Core.Api/IAsyncStreamWriter.cs

@ -13,7 +13,7 @@
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks>net45;netstandard1.5;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net45;netstandard1.5;netstandard2.0;netstandard2.1</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

@ -20,6 +20,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Grpc.Core
@ -36,6 +37,26 @@ namespace Grpc.Core
/// <param name="message">The message to be written. Cannot be null.</param>
Task WriteAsync(T message);
#if NETSTANDARD2_1_OR_GREATER
/// <summary>
/// Writes a message asynchronously. Only one write can be pending at a time.
/// </summary>
/// <param name="message">The message to be written. Cannot be null.</param>
/// <param name="cancellationToken">Cancellation token that can be used to cancel the operation.</param>
Task WriteAsync(T message, CancellationToken cancellationToken)
{
if (cancellationToken.CanBeCanceled)
{
// Note to implementors:
// Add a netstandard2.1 or greater target to your library and override
// WriteAsync(T, CancellationToken) on stream writer to use the cancellation token.
throw new NotSupportedException("Cancellation of stream writes is not supported by this gRPC implementation.");
}
return WriteAsync(message);
}
#endif
/// <summary>
/// Write options that will be used for the next write.
/// If null, default options will be used.

Loading…
Cancel
Save