public Future <Tuple2 <T, T2> > Join <T2> (Future <T2> future) { var f = new FutureImpl <Tuple2 <T, T2> >(); this.OnComplete(f1 => { if (future.Done) { if (future.Success && this.Success) { f.SetResult(Tuples.Tuple(this.result, future.Get())); } else if (future.Success && this.HasError) { f.SetError(this.error); } else if (future.HasError && this.Success) { f.SetError(this.error); } else { f.SetError(new MultiException(this.error, future.Error)); } } }); future.OnComplete(f2 => { if (this.Done) { if (future.Success && this.Success) { f.SetResult(Tuples.Tuple(this.result, future.Get())); } else if (future.Success && this.HasError) { f.SetError(this.error); } else if (future.HasError && this.Success) { f.SetError(this.error); } else { f.SetError(new MultiException(this.error, future.Error)); } } }); return(f); }
public Future <T> Recover(MapFunc <Exception, T> recoverFunc) { var f = new FutureImpl <T>(); OnComplete(obj => { if (obj.Success) { f.SetResult(result); } else { f.SetResult(recoverFunc(error)); } }); return(f); }
public Future <To> Map <To> (MapFunc <T, To> mapFunc) { var f = new FutureImpl <To>(); OnComplete(obj => { if (obj.Success) { f.SetResult(mapFunc(result)); } else { f.SetError(error); } }); return(f); }
public Future <T> Select(Future <T> future) { var f = new FutureImpl <T>(); this.OnComplete(r => { if (!f.Done) { if (r.Success) { f.SetResult(r.Result); } else { if (future.HasError) { f.SetError(new MultiException(future.Error, this.Error)); } } } }); future.OnComplete(r => { if (!f.Done) { if (r.Success) { f.SetResult(r.Result); } else { if (this.HasError) { f.SetError(new MultiException(this.Error, future.Error)); } } } }); return(f); }