コード例 #1
0
        public ICompletableFuture <R> Zip <R, U>(ICompletableFuture <U> other, Func <T, U, R> combinator)
        {
            if (this.result.HasError)
            {
                return(new CompletedFuture <R>(Results.InError <R>(result.Exception)));
            }

            if (other.IsDone())
            {
                var otherResult = other.GetResult();

                if (otherResult.HasError)
                {
                    return(new CompletedFuture <R>(Results.InError <R>(otherResult.Exception)));
                }
                else
                {
                    try
                    {
                        return(new CompletedFuture <R>(Results.InValue <R>(combinator(result.Payload, otherResult.Payload))));
                    }
                    catch (Exception e)
                    {
                        return(new CompletedFuture <R>(Results.InError <R>(e)));
                    }
                }
            }
            else
            {
                return(other.Zip(this, (u, t) => combinator(t, u)));
            }
        }
コード例 #2
0
        public ICompletableFuture <R> Zip <R, U>(ICompletableFuture <U> other, Func <T, U, R> combinator)
        {
            IAsyncTaskBasedFuture <U> asyncTask = other as IAsyncTaskBasedFuture <U>;

            if (asyncTask == null)
            {
                throw new Exception("Combined future is not asyncronous");
            }
            return(new TaskFuture <R>(this.task.Then(t => asyncTask.GetTask().Then(u => t.Zip(u, combinator)))));
        }
コード例 #3
0
        private static ICompletableFuture <IEnumerable <P> > Reduce <P>(IEnumerable <ICompletableFuture <P> > source)
        {
            ICompletableFuture <List <P> > root = CompletableFuture.CompletedWithValue(new List <P>());

            return(source.Aggregate(root, (a, b) => a.Zip(b, (x, y) => { x.Add(y); return x; })));
        }