Skip to content

Instantly share code, notes, and snippets.

@LironHazan
Created January 10, 2018 12:26
Show Gist options
  • Save LironHazan/2a1905d59fb729a50798d121bc099bc7 to your computer and use it in GitHub Desktop.
Save LironHazan/2a1905d59fb729a50798d121bc099bc7 to your computer and use it in GitHub Desktop.
I needed to do something similar to the promise.all just with observables and came up with forkJoin, here's an example
geSomethingById(id: number): Observable<any[]> {
return this.http.get<any[]>(
`api/something?id=${id}`);
}
getSomething(ids) {
const ids = this.getListOfVersionIds(selectedArtifacts)
const requests = ids.reduce((acc, id) => {
acc.push(this.geSomethingById(id));
return acc;
}, []);
return forkJoin(requests)
.subscribe((files) => {
return files;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment