In the Observables forkJoin documentation, it says that args can be an array but it doesn't list an example doing so:
https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/operators/forkjoin.md
I have tried a function similar to what I listed (below) but came up with an error:
:3000/angular2/src/platform/browser/browser_adapter.js:76
EXCEPTION: TypeError: Observable_1.Observable.forkJoin is not a function
A sheared version of my function below:
processStuff( inputObject ) {
let _self = this;
return new Observable(function(observer) {
let observableBatch = [];
inputObject.forEach(function(componentarray, key) {
observableBatch.push(_self.http.get(key + '.json').map((res: Response) => res.json()));
});
Observable.forkJoin(
observableBatch
// );
).subscribe(() => {
observer.next();
observer.complete();
});
});
}
The root of my question is related to a loop to end before proceeding as asked here: Angular2 Observable - how to wait for all function calls in a loop to end before proceeding?
But I haven't fully mastered the correct use of forkJoin with an array and the right syntax to do so.
I am very grateful for help you could offer.
NOTE: EXAMPLE OF THIRD FUNCTION THAT RETURNS AN OBSERVABLE
thirdFunction() {
let _self = this;
return Observable.create((observer) => {
// return new Observable(function(observer) {
...
observer.next(responseargs);
observer.complete();
});
}
processStuff(inputObject) {
let _self = this;
let observableBatch = [];
inputObject.forEach((componentarray, key) => {
observableBatch.push(_self.thirdFunction().map((res: Response) => res.json()));
});
return Observable.forkJoin(observableBatch);
}
elsewhere() {
this.processStuff(inputObject)
.subscribe()
}
Observable.forkJoin([http.get(), http.get(), http.get(), etc]).subscribe((res) => ...)
See also https://mcmap.net/q/182609/-promise-all-with-rxjs – Succulentimport 'rxjs/add/observable/forkJoin'
orimport 'rxjs/Rx'
? – Belldas