Beispiel #1
0
        public static Future <Pair <A, B> > Zip <A, B>(this Future <A> future, Future <B> other)
        {
            return(Future.Async <Pair <A, B> >(cb =>
            {
                var latch = new CountdownEvent(2);
                var resA = default(A);
                var resB = default(B);
                Action next =
                    () =>
                {
                    latch.Wait();
                    cb(Pair.Create(resA, resB));
                };

                future.RunAsync(
                    a =>
                {
                    resA = a;
                    latch.Signal();
                    next();
                });
                other.Callback(
                    b =>
                {
                    resB = b;
                    latch.Signal();
                });
            },
                                               future.Strategy));
        }
Beispiel #2
0
 public static Future <B> Bind <A, B>(this Future <A> future, Func <A, Future <B> > f)
 {
     return(new Future <B>(
                cb => future.Callback(a => f(a).Callback(cb)),
                future.Strategy));
 }
Beispiel #3
0
 public Future <B> Map <A, B>(Future <A> future, Func <A, B> f)
 {
     return(new Future <B>(
                cb => future.Callback(a => cb(f(a))),
                future.Strategy));
 }