本文整理汇总了C#中Grpc.Core.CallOptions.WithCancellationToken方法的典型用法代码示例。如果您正苦于以下问题:C# CallOptions.WithCancellationToken方法的具体用法?C# CallOptions.WithCancellationToken怎么用?C# CallOptions.WithCancellationToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Grpc.Core.CallOptions
的用法示例。
在下文中一共展示了CallOptions.WithCancellationToken方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WithMethods
public void WithMethods()
{
var options = new CallOptions();
var metadata = new Metadata();
Assert.AreSame(metadata, options.WithHeaders(metadata).Headers);
var deadline = DateTime.UtcNow;
Assert.AreEqual(deadline, options.WithDeadline(deadline).Deadline.Value);
var cancellationToken = new CancellationTokenSource().Token;
Assert.AreEqual(cancellationToken, options.WithCancellationToken(cancellationToken).CancellationToken);
var writeOptions = new WriteOptions();
Assert.AreSame(writeOptions, options.WithWriteOptions(writeOptions).WriteOptions);
var propagationToken = new ContextPropagationToken(CallSafeHandle.NullInstance, DateTime.UtcNow,
CancellationToken.None, ContextPropagationOptions.Default);
Assert.AreSame(propagationToken, options.WithPropagationToken(propagationToken).PropagationToken);
var credentials = new FakeCallCredentials();
Assert.AreSame(credentials, options.WithCredentials(credentials).Credentials);
// Check that the original instance is unchanged.
Assert.IsNull(options.Headers);
Assert.IsNull(options.Deadline);
Assert.AreEqual(CancellationToken.None, options.CancellationToken);
Assert.IsNull(options.WriteOptions);
Assert.IsNull(options.PropagationToken);
Assert.IsNull(options.Credentials);
}
示例2: WithMethods
public void WithMethods()
{
var options = new CallOptions();
var metadata = new Metadata();
Assert.AreSame(metadata, options.WithHeaders(metadata).Headers);
var deadline = DateTime.UtcNow;
Assert.AreEqual(deadline, options.WithDeadline(deadline).Deadline.Value);
var token = new CancellationTokenSource().Token;
Assert.AreEqual(token, options.WithCancellationToken(token).CancellationToken);
// Change original instance is unchanged.
Assert.IsNull(options.Headers);
Assert.IsNull(options.Deadline);
Assert.AreEqual(CancellationToken.None, options.CancellationToken);
Assert.IsNull(options.WriteOptions);
Assert.IsNull(options.PropagationToken);
Assert.IsNull(options.Credentials);
}