make CallFlags internal, expose WaitForReady

pull/8828/head
Jan Tattermusch 8 years ago
parent 43416dac68
commit 058f555b7e
  1. 11
      src/csharp/Grpc.Core.Tests/CallOptionsTest.cs
  2. 34
      src/csharp/Grpc.Core/CallOptions.cs
  3. 2
      src/csharp/Grpc.Core/Grpc.Core.csproj
  4. 6
      src/csharp/Grpc.Core/Internal/CallFlags.cs

@ -98,5 +98,16 @@ namespace Grpc.Core.Tests
Assert.AreEqual(token, new CallOptions(propagationToken: propagationToken2).Normalize().CancellationToken);
Assert.Throws(typeof(ArgumentException), () => new CallOptions(cancellationToken: token, propagationToken: propagationToken2).Normalize());
}
[Test]
public void WaitForReady()
{
var callOptions = new CallOptions();
Assert.IsFalse(callOptions.IsWaitForReady);
Assert.AreEqual(CallFlags.WaitForReady, callOptions.WithWaitForReady().Flags);
Assert.IsTrue(callOptions.WithWaitForReady().IsWaitForReady);
Assert.IsFalse(callOptions.WithWaitForReady(true).WithWaitForReady(false).IsWaitForReady);
}
}
}

@ -61,10 +61,8 @@ namespace Grpc.Core
/// <param name="writeOptions">Write options that will be used for this call.</param>
/// <param name="propagationToken">Context propagation token obtained from <see cref="ServerCallContext"/>.</param>
/// <param name="credentials">Credentials to use for this call.</param>
/// <param name="flags">Flags to use for this call.</param>
public CallOptions(Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken),
WriteOptions writeOptions = null, ContextPropagationToken propagationToken = null, CallCredentials credentials = null,
CallFlags flags = default(CallFlags))
WriteOptions writeOptions = null, ContextPropagationToken propagationToken = null, CallCredentials credentials = null)
{
this.headers = headers;
this.deadline = deadline;
@ -72,7 +70,7 @@ namespace Grpc.Core
this.writeOptions = writeOptions;
this.propagationToken = propagationToken;
this.credentials = credentials;
this.flags = flags;
this.flags = default(CallFlags);
}
/// <summary>
@ -129,10 +127,20 @@ namespace Grpc.Core
get { return this.credentials; }
}
/// <summary>
/// If <c>true</c> and and channel is in <c>ChannelState.TransientFailure</c>, the call will attempt waiting for the channel to recover
/// instead of failing immediately (which is the default "FailFast" semantics).
/// Note: experimental API that can change or be removed without any prior notice.
/// </summary>
public bool IsWaitForReady
{
get { return (this.flags & CallFlags.WaitForReady) == CallFlags.WaitForReady; }
}
/// <summary>
/// Flags to use for this call.
/// </summary>
public CallFlags Flags
internal CallFlags Flags
{
get { return this.flags; }
}
@ -209,12 +217,26 @@ namespace Grpc.Core
return newOptions;
}
/// <summary>
/// Returns new instance of <see cref="CallOptions"/> with "WaitForReady" semantics enabled/disabled.
/// <see cref="IsWaitForReady"/>.
/// Note: experimental API that can change or be removed without any prior notice.
/// </summary>
public CallOptions WithWaitForReady(bool waitForReady = true)
{
if (waitForReady)
{
return WithFlags(this.flags | CallFlags.WaitForReady);
}
return WithFlags(this.flags & ~CallFlags.WaitForReady);
}
/// <summary>
/// Returns new instance of <see cref="CallOptions"/> with
/// <c>Flags</c> set to the value provided. Values of all other fields are preserved.
/// </summary>
/// <param name="flags">The call flags.</param>
public CallOptions WithFlags(CallFlags flags)
internal CallOptions WithFlags(CallFlags flags)
{
var newOptions = this;
newOptions.flags = flags;

@ -48,7 +48,6 @@
<Compile Include="AsyncServerStreamingCall.cs" />
<Compile Include="AsyncAuthInterceptor.cs" />
<Compile Include="CallCredentials.cs" />
<Compile Include="CallFlags.cs" />
<Compile Include="IClientStreamWriter.cs" />
<Compile Include="Internal\NativeMethods.cs" />
<Compile Include="Internal\PlatformApis.cs" />
@ -141,6 +140,7 @@
<Compile Include="Logging\LogLevelFilterLogger.cs" />
<Compile Include="Internal\RequestCallContextSafeHandle.cs" />
<Compile Include="Utils\TaskUtils.cs" />
<Compile Include="Internal\CallFlags.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Grpc.Core.project.json" />

@ -33,13 +33,13 @@
using System;
namespace Grpc.Core
namespace Grpc.Core.Internal
{
/// <summary>
/// Flags for various call behaviors (client-side only).
/// Flags to enable special call behaviors (client-side only).
/// </summary>
[Flags]
public enum CallFlags
internal enum CallFlags
{
/// <summary>
/// The call is idempotent (retrying the call doesn't change the outcome of the operation).
Loading…
Cancel
Save