Skip to content

Instantly share code, notes, and snippets.

@ahsquared
Last active December 1, 2016 14:59
Show Gist options
  • Save ahsquared/0c8041a702c9459f72ad256aa4ea6588 to your computer and use it in GitHub Desktop.
Save ahsquared/0c8041a702c9459f72ad256aa4ea6588 to your computer and use it in GitHub Desktop.
Set up a queue of Observables with RxJS
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