本文整理汇总了C#中TaskCompletionSource.setUncancellable方法的典型用法代码示例。如果您正苦于以下问题:C# TaskCompletionSource.setUncancellable方法的具体用法?C# TaskCompletionSource.setUncancellable怎么用?C# TaskCompletionSource.setUncancellable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TaskCompletionSource
的用法示例。
在下文中一共展示了TaskCompletionSource.setUncancellable方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DisconnectAsync
public Task DisconnectAsync()
{
var promise = new TaskCompletionSource();
if (!promise.setUncancellable())
{
return promise.Task;
}
bool wasActive = this.channel.Active;
try
{
this.channel.DoDisconnect();
}
catch (Exception t)
{
this.SafeSetFailure(promise, t);
this.CloseIfClosed();
return promise.Task;
}
if (wasActive && !this.channel.Active)
{
this.InvokeLater(() => this.channel.pipeline.FireChannelInactive());
}
this.SafeSetSuccess(promise);
this.CloseIfClosed(); // doDisconnect() might have closed the channel
return promise.Task;
}
示例2: CloseAsync
public Task CloseAsync() //CancellationToken cancellationToken)
{
var promise = new TaskCompletionSource();
if (!promise.setUncancellable())
{
return promise.Task;
}
//if (cancellationToken.IsCancellationRequested)
//{
// return TaskEx.Cancelled;
//}
if (this.outboundBuffer == null)
{
// Only needed if no VoidChannelPromise.
if (promise != TaskCompletionSource.Void)
{
// This means close() was called before so we just register a listener and return
return this.channel.closeFuture.Task;
}
return promise.Task;
}
if (this.channel.closeFuture.Task.IsCompleted)
{
// Closed already.
Util.SafeSetSuccess(promise);
return promise.Task;
}
bool wasActive = this.channel.Active;
ChannelOutboundBuffer buffer = this.outboundBuffer;
this.outboundBuffer = null; // Disallow adding any messages and flushes to outboundBuffer.
IEventExecutor closeExecutor = null; // todo closeExecutor();
if (closeExecutor != null)
{
closeExecutor.Execute(() =>
{
try
{
// Execute the close.
this.DoClose0(promise);
}
finally
{
// Call invokeLater so closeAndDeregister is executed input the EventLoop again!
this.InvokeLater(() =>
{
// Fail all the queued messages
buffer.FailFlushed(ClosedChannelException,
false);
buffer.Close(ClosedChannelException);
this.FireChannelInactiveAndDeregister(wasActive);
});
}
});
}
else
{
try
{
// Close the channel and fail the queued messages input all cases.
this.DoClose0(promise);
}
finally
{
// Fail all the queued messages.
buffer.FailFlushed(ClosedChannelException, false);
buffer.Close(ClosedChannelException);
}
if (this.inFlush0)
{
this.InvokeLater(() => this.FireChannelInactiveAndDeregister(wasActive));
}
else
{
this.FireChannelInactiveAndDeregister(wasActive);
}
}
return promise.Task;
}
示例3: Register0
void Register0(TaskCompletionSource promise)
{
try
{
// check if the channel is still open as it could be closed input the mean time when the register
// call was outside of the eventLoop
if (!promise.setUncancellable() || !this.EnsureOpen(promise))
{
Util.SafeSetFailure(promise, ClosedChannelException);
return;
}
bool firstRegistration = this.neverRegistered;
this.channel.DoRegister();
this.neverRegistered = false;
this.channel.registered = true;
this.channel.eventLoop.AcceptNewTasks();
Util.SafeSetSuccess(promise);
this.channel.pipeline.FireChannelRegistered();
// Only fire a channelActive if the channel has never been registered. This prevents firing
// multiple channel actives if the channel is deregistered and re-registered.
if (firstRegistration && this.channel.Active)
{
this.channel.pipeline.FireChannelActive();
}
}
catch (Exception t)
{
// Close the channel directly to avoid FD leak.
this.CloseForcibly();
this.channel.closeFuture.Complete();
Util.SafeSetFailure(promise, t);
}
}