コード例 #1
0
        public AsyncRequestHandlerWhenAll(IAsyncRequestHandlerCore <TRequest, TResponse>[] handlers, TRequest request, CancellationToken cancellationtoken)
        {
            result = new TResponse[handlers.Length];

            for (int i = 0; i < handlers.Length; i++)
            {
                try
                {
                    var awaiter = handlers[i].InvokeAsync(request, cancellationtoken).GetAwaiter();
                    if (awaiter.IsCompleted)
                    {
                        result[i] = awaiter.GetResult();
                        goto SUCCESSFULLY;
                    }
                    else
                    {
                        AwaiterNode.RegisterUnsafeOnCompleted(this, awaiter, i);
                        continue;
                    }
                }
                catch (Exception ex)
                {
                    exception = ExceptionDispatchInfo.Capture(ex);
                    TryInvokeContinuation();
                    return;
                }

SUCCESSFULLY:
                IncrementSuccessfully();
            }
        }
コード例 #2
0
        public AsyncHandlerWhenAll(IAsyncMessageHandler <T>?[] handlers, T message, CancellationToken cancellationtoken)
        {
            taskCount = handlers.Length;

            foreach (var item in handlers)
            {
                if (item == null)
                {
                    IncrementSuccessfully();
                }
                else
                {
                    try
                    {
                        var awaiter = item.HandleAsync(message, cancellationtoken).GetAwaiter();
                        if (awaiter.IsCompleted)
                        {
                            awaiter.GetResult();
                            goto SUCCESSFULLY;
                        }
                        else
                        {
                            AwaiterNode.RegisterUnsafeOnCompleted(this, awaiter);
                            continue;
                        }
                    }
                    catch (Exception ex)
                    {
                        exception = ExceptionDispatchInfo.Capture(ex);
                        TryInvokeContinuation();
                        return;
                    }

SUCCESSFULLY:
                    IncrementSuccessfully();
                }
            }
        }