Last active
December 1, 2016 14:59
-
-
Save ahsquared/0c8041a702c9459f72ad256aa4ea6588 to your computer and use it in GitHub Desktop.
Set up a queue of Observables with RxJS
This file contains 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
stream$.flatMap(array => { | |
let observablesArray = array.map(arrayItem => { | |
// map over array returning observables - this can be nested and flattened | |
return Rx.Observable.fromPromise(promiseFunction(arrayItem)) | |
// whatever other rx-y things you need to do | |
.retry(2) | |
// what do we really want to do with these errors | |
.catch(e => { | |
return Rx.Observable.of({ | |
errorStatus: true, | |
error: e | |
}); | |
}); | |
}); | |
// zip will return when all promises return - order not guaranteed | |
// use concat instead of zip if order matters | |
return Rx.Observable.zip.apply(null, observablesArray); | |
}).subscribe(...); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment