/// <summary>
        /// Sends the asynchronous.
        /// </summary>
        /// <param name="handleProxy">The handle proxy.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public Task SendAsync(HandleProxy handleProxy, CancellationToken cancellationToken)
        {
            if (IsStarted is false)
            {
                throw new InvalidOperationException("ActionBlock is not started, call Start method first and retry.");
            }

            return(_handleProxyBlock.SendAsync(handleProxy, cancellationToken));
        }
        void Process(IChannelHandlerContext ctx, IHttpRequest request)
        {
            string uri = request.Uri;

            Task.Run(async() =>
            {
                HandleProxy.AddRequest(ctx, request, this);
            }
                     )
            ;
        }
示例#3
0
        /// <inheritdoc/>
        public ValueTask EnqueueAsync(HandleProxy handleProxy, CancellationToken cancellationToken)
        {
            _ = handleProxy ?? throw new ArgumentNullException(nameof(handleProxy));

            cancellationToken.ThrowIfCancellationRequested();

            _handleProxyDelegates.Enqueue(handleProxy);

            _semaphore.Release();

            return(new ValueTask());
        }
示例#4
0
        public static async Task SafeInvokeAsync(this HandleProxy handleProxy, ILogger logger, CancellationToken cancellationToken = default)
        {
            _ = handleProxy ?? throw new ArgumentNullException(nameof(handleProxy));

            try
            {
                await handleProxy(cancellationToken).ConfigureAwait(false);
            }
            catch (Exception ex) when(ex is OperationCanceledException or ObjectDisposedException)
            {
                logger?.LogInformation(ex, $"{nameof(HandleProxy)} delegate cancelled.");
            }
            catch (Exception ex)
            {
                logger?.LogError(ex, $"{nameof(HandleProxy)} delegate failed.");
            }
        }
        public void SafeInvokeAsync_throws_when_proxy_is_null()
        {
            HandleProxy proxy = null;

            Func <Task> createError = () => proxy.SafeInvokeAsync(logger: null, cancellationToken: default);