Skip to content
Advertisement

Managing promises in RXJS observables

I’ve poked about SO and found many similar questions/answers but I may be missing something in my basic understanding on how to work with with this stack.

I’m working on a react native project along with RXJS/obervables. At some point I doing file downloads, this part is not a problem. A combo of pre-existing axios-rxjs and react-native-file-system get me where I want. The issue is I’m not sure how to handle it cleanly without async/await which I understand is an anti-pattern.

I want to transform this working code into a clean obervable-style flow.

I’ve implemented an Epic that does the operations I want as such:

JavaScript

I’ve tried splitting this into several pipes, for example, I tried splitting the READ operation into a previous pipe but it ends up looking very verbose. Is there not a clean simple way to “hold” until the promises are done so I can make decisions based on their result?

What would be considered cleaner in this situation?

Advertisement

Answer

You can try something like this. It should be roughly equivalent to what you’ve written above.

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement