当前位置: 首页>>代码示例>>C#>>正文


C# TaskCompletionSource.setUncancellable方法代码示例

本文整理汇总了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;
            }
开发者ID:dalong123,项目名称:DotNetty,代码行数:30,代码来源:AbstractChannel.cs

示例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;
            }
开发者ID:dalong123,项目名称:DotNetty,代码行数:82,代码来源:AbstractChannel.cs

示例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);
     }
 }
开发者ID:dalong123,项目名称:DotNetty,代码行数:33,代码来源:AbstractChannel.cs


注:本文中的TaskCompletionSource.setUncancellable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。