Angular2 Observable – Await multiple function calls before proceeding

I have been doing this with forkJoin import {Observable} from ‘rxjs/Observable’; import ‘rxjs/add/observable/forkJoin’; Observable.forkJoin( this.http.get(‘./friends.json’).map((res: Response) => res.json()), this.http.get(‘./customer.json’).map((res: Response) => res.json()) ) .subscribe(res => this.combined = {friends: res[0].friends, customer: res[1]}); Some more info here: http://www.syntaxsuccess.com/viewarticle/angular-2.0-and-http

Caching a promise object in AngularJS service

Is this the right approach? Yes. The use of memoisation on functions that return promises a common technique to avoid the repeated execution of asynchronous (and usually expensive) tasks. The promise makes the caching easy because one does not need to distinguish between ongoing and finished operations, they’re both represented as (the same) promise for … Read more

Get state of Angular deferred?

Update: Due to refactoring of $q this is now possible although not documented: promise.$$state.status === 0 // pending promise.$$state.status === 1 // resolved promise.$$state.status === 2 // rejected Original: Unlike most promise libraries (Bluebird,Q, when, RSVP etc), $q does not expose a synchronous inspection API. There is no way to achieve this from the outside. … Read more

What happens with $q.all() when some calls work and others fail?

I believe since the promise library is based on Q implementation, as soon as the first promise gets rejected, the reject callback is called with the error. It does not wait for other promises to resolved. See documentation of Q https://github.com/kriskowal/q. For Q.all this is what is mentioned The all function returns a promise for … Read more

tech