Created
March 12, 2017 13:42
-
-
Save BerkeleyTrue/1556c5f3748ee3d8d7fef02dcd04ca31 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const serviceValues = [ 2, 3, 4 ]; | |
// convert values array into a stream of individual values: Obs[...num] | |
return Observable.of(serviceValues) | |
// call service on each value and get Observable in return: Obs[Obs[newValFromService]] | |
.map(val => serviceApi(val)) | |
// convert stream of observables into a stream of a single array of observables Obs[ [Obs[newVal]] ] | |
.toArray() | |
// trigger all the service calls with maximum concurrenct | |
.switchMap((serviceCalls) => Observable.combineLatest(serviceCalls)) | |
.subscribe(newVals => console.log('new values from server: ', newVals)) // [...{id: 2, ...data}, {id: 3, ...dat}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment