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)); }
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)); }
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)); }