Exemplo n.º 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));
        }
Exemplo n.º 2
0
Arquivo: Bind.cs Projeto: jedahu/Jib
 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));
 }
Exemplo n.º 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));
 }