Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- flatMap<S>(f: (T) => Future<S>): Future<S> {
- let p = new CompletablePromise<S>();
- let fut = p.future;
- this.next = (v) => {
- if (v.isSuccess()) {
- let result: Try<Future<S>> = Try.doWork(() => f(v.get()));
- if (result.isSuccess()) {
- let nextFut = result.get();
- nextFut.onComplete((v) => {
- p.complete(v)
- })
- } else {
- p.complete(result as Try<any> as Try<S>)
- }
- } else {
- p.complete(v as Try<any> as Try<S>);
- }
- };
- return fut;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement