Exemplo n.º 1
0
        /// <summary>
        /// Completes the block.  This must only be called once, and only once all of the completion conditions are met.
        /// </summary>
        private void CompleteBlockOncePossible()
        {
            Contract.Assert(_completionReserved, "Should only invoke once completion has been reserved.");

            // Dump any messages that might remain in the queue, which could happen if we completed due to exceptions.
            TInput dumpedMessage;

            while (_messages.TryDequeue(out dumpedMessage))
            {
                ;
            }

            // Complete the completion task
            bool result;

            if (_exceptions != null)
            {
                Exception[] exceptions;
                lock (_exceptions) exceptions = _exceptions.ToArray();
                result = CompletionSource.TrySetException(exceptions);
            }
            else
            {
                result = CompletionSource.TrySetResult(default(VoidResult));
            }
            Contract.Assert(result, "Expected completion task to not yet be completed");
            // We explicitly do not set the _activeTask to null here, as that would
            // allow for races where a producer calling OfferMessage could end up
            // seeing _activeTask as null and queueing a new consumer task even
            // though the block has completed.

#if FEATURE_TRACING
            DataflowEtwProvider etwLog = DataflowEtwProvider.Log;
            if (etwLog.IsEnabled())
            {
                etwLog.DataflowBlockCompleted(_owningTarget);
            }
#endif
        }
Exemplo n.º 2
0
 public void SetException(Exception ex)
 {
     CompletionSource.TrySetException(ex);
 }
 protected override void Failure(Exception exception)
 {
     CompletionSource.TrySetException(exception);
 }
Exemplo n.º 4
0
 public override void ExceptionCaught(IChannelHandlerContext ctx, Exception exception)
 {
     Console.WriteLine("Exception: " + exception);
     CompletionSource.TrySetException(exception);
     ctx.CloseAsync();
 }