本文整理汇总了C#中TaskCompletionSource.SetUncancellable方法的典型用法代码示例。如果您正苦于以下问题:C# TaskCompletionSource.SetUncancellable方法的具体用法?C# TaskCompletionSource.SetUncancellable怎么用?C# TaskCompletionSource.SetUncancellable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TaskCompletionSource
的用法示例。
在下文中一共展示了TaskCompletionSource.SetUncancellable方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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._closeTask.Task;
}
return promise.Task;
}
if (this._channel._closeTask.Task.IsCompleted)
{
// Closed already.
PromiseUtil.SafeSetSuccess(promise, Logger);
return promise.Task;
}
bool wasActive = this._channel.IsActive;
ChannelOutboundBuffer buffer = this.outboundBuffer;
this.outboundBuffer = null; // Disallow adding any messages and flushes to outboundBuffer.
try
{
// Close the channel and fail the queued messages input all cases.
this.DoClose0(promise);
}
finally
{
// Fail all the queued messages.
buffer.FailFlushed(ClosedChannelException.Instance, false);
buffer.Close(ClosedChannelException.Instance);
}
if (this.inFlush0)
{
this.InvokeLater(() => this.FireChannelInactiveAndDeregister(wasActive));
}
else
{
this.FireChannelInactiveAndDeregister(wasActive);
}
return promise.Task;
}
示例2: DisconnectAsync
public Task DisconnectAsync()
{
var promise = new TaskCompletionSource();
if (!promise.SetUncancellable())
{
return promise.Task;
}
bool wasActive = this._channel.IsActive;
try
{
this._channel.DoDisconnect();
}
catch (Exception t)
{
SafeSetFailure(promise, t);
this.CloseIfClosed();
return promise.Task;
}
if (wasActive && !this._channel.IsActive)
{
this.InvokeLater(() => this._channel._pipeline.FireChannelInactive());
}
this.SafeSetSuccess(promise);
this.CloseIfClosed(); // doDisconnect() might have closed the channel
return promise.Task;
}
示例3: CloseAsync
Task CloseAsync(Exception cause, bool notify)
{
var promise = new TaskCompletionSource();
if (!promise.SetUncancellable())
{
return promise.Task;
}
ChannelOutboundBuffer outboundBuffer = this.outboundBuffer;
if (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, Logger);
return promise.Task;
}
bool wasActive = this.channel.Active;
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
outboundBuffer.FailFlushed(cause, notify);
outboundBuffer.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.
outboundBuffer.FailFlushed(cause, notify);
outboundBuffer.Close(ClosedChannelException);
}
if (this.inFlush0)
{
this.InvokeLater(() => this.FireChannelInactiveAndDeregister(wasActive));
}
else
{
this.FireChannelInactiveAndDeregister(wasActive);
}
}
return promise.Task;
}
示例4: 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() || !EnsureOpen(promise))
{
PromiseUtil.SafeSetFailure(promise, ClosedChannelException.Instance, Logger);
return;
}
bool firstRegistration = this.neverRegistered;
this._channel.DoRegister();
this.neverRegistered = false;
this._channel._registered = true;
this._channel._eventLoop.AcceptNewTasks();
PromiseUtil.SafeSetSuccess(promise, Logger);
_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.IsActive)
{
_channel._pipeline.FireChannelActive();
}
}
catch (Exception t)
{
// Close the channel directly to avoid FD leak.
CloseForcibly();
_channel._closeTask.Complete();
PromiseUtil.SafeSetFailure(promise, t, Logger);
}
}
示例5: 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, Logger);
return;
}
bool firstRegistration = this.neverRegistered;
this.channel.DoRegister();
this.neverRegistered = false;
this.channel.registered = true;
if (firstRegistration)
{
// We are now registered to the EventLoop. It's time to call the callbacks for the ChannelHandlers,
// that were added before the registration was done.
this.channel.pipeline.CallHandlerAddedForAllHandlers();
}
Util.SafeSetSuccess(promise, Logger);
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 (this.channel.Active)
{
if (firstRegistration)
{
this.channel.pipeline.FireChannelActive();
}
else if (this.channel.Configuration.AutoRead)
{
// This channel was registered before and autoRead() is set. This means we need to begin read
// again so that we process inbound data.
//
// See https://github.com/netty/netty/issues/4805
this.BeginRead();
}
}
}
catch (Exception t)
{
// Close the channel directly to avoid FD leak.
this.CloseForcibly();
this.channel.closeFuture.Complete();
Util.SafeSetFailure(promise, t, Logger);
}
}