I need to requests to load multiple movies by their ids. Each request returns a separate Observable. I have the following code:
getMoviesDataByImdbIds(ids: number[]):Observable<IMovie[]> {
return Observable.zip(ids.map( id => {
let params = new HttpParams().set('i', this.getIMDBIdString(id)).set('apikey', API_KEY);
return this.http.get(API_URL, {params}).map( data => {
return this.extractMovieData(data);
})
}));
}
Since there might be quite many ids, the whole operation takes quite a while. And the result is only returned once all the requests complete.
Is it possible to make output Observable emit the array every time a new request is complete? Like so:
1 complete -> [{movie1}]
2 complete -> [{movie1}, {movie2}]
3 complete -> [{movie1}, {movie2}, {movie3}],
etc.