Example #1
0
 public static void Terminate <T>(
     this IWritableChannel <T> channel,
     Exception error = null)
 {
     if (!channel.TryTerminate(error))
     {
         throw new OperationCanceledException();
     }
 }
Example #2
0
        private async Task ProcessAsync()
        {
            try
            {
                if (_beginConsumeAsync != null)
                {
                    await _beginConsumeAsync(_out).ConfigureAwait(false);
                }
                await _buffer.ConsumeBufferAsync(PropagateAsync, _disposeRejected).ConfigureAwait(false);

                if (_completeConsumeAsync != null)
                {
                    await _completeConsumeAsync(_out).ConfigureAwait(false);
                }
            }
            catch (Exception ex)
            {
                _buffer.Out.TryTerminate(ex);
                if (_terminateConsumeAsync != null)
                {
                    await _terminateConsumeAsync(ex, _out).IgnoreExceptions().ConfigureAwait(false);
                }
                throw;
            }
            finally
            {
                try
                {
                    await _buffer.In.Completion.ConfigureAwait(false);

                    _out.TryComplete();
                }
                catch (Exception ex)
                {
                    _out.TryTerminate(ex);
                    throw;
                }
                finally
                {
                    await _out.Completion.ConfigureAwait(false);
                }
            }
        }
Example #3
0
        private static async Task PropagateAsync(IReadableChannel <TransportMessageFrame> channel1, IWritableChannel <TransportMessageFrame> channel2)
        {
            try
            {
                while (true)
                {
                    var result = await channel1.TryReadAsync().ConfigureAwait(false);

                    if (!result.HasValue)
                    {
                        break;
                    }
                    await channel2.WriteAsync(result.Value).ConfigureAwait(false);
                }
                channel2.TryComplete();
            }
            catch (Exception ex)
            {
                channel2.TryTerminate(ex);
            }
        }
Example #4
0
 public static async Task TerminateAsync <T>(this IWritableChannel <T> channel, Exception error = null)
 {
     channel.TryTerminate(error);
     await channel.Completion.ConfigureAwait(false);
 }