Skip to content
Advertisement

Implement for-await-of statement in RxJS

I have the following statement:

JavaScript

client.list() returns an async iterable iterator, and expects the use of for await…of to resolve the promises. I would like to incorporate the code into an existing rxjs pipe that instantiates the client.

I looked everywhere and I couldn’t figure out how to do so without resolving the promise inside the pipe rather than converting into observables.

Any help would be appreciated!

Advertisement

Answer

I can’t find an existing rxjs operator, but it doesn’t seem too difficult to make your own. When integrating other APIs with observables you can interact with the API within the function passed to the observable constructor. This allows a lot of flexibility when triggering next/error/complete.

Edit – I’ve added a second option for doing this, using rxjs operators and avoiding explicitly calling next/error/complete.

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