Kotlin-multiplatform : how to use Kotlin Flow in Javascript

I have created a kotlin multi-platform library to design Domain layer that targets JVM and JS (nodejs and browser). Domain depends on UseCase, UseCase depends on Repository, Repository depends on Service and Database. AFAIK, Kotlin Coroutines work across platforms (JS/JVM/Native).

I have a function that returns Flow , instead of Promise .

fun getUserList() : Flow<List<User>>{...}

Reason is, I want to update UI as soon as there is any change in Database. On JVM (or Android), I know how to consume Flow. But don’t understand how to consume it from plain Javascript(or TypeScript) (not Kotlin-JS). Even I didn’t find any supporting article that explains about using Flow for JS.

Can anyone help me out with this? Any help will be appreciated!

PS: My Javascript Skills are intermediate :stuck_out_tongue:

Using coroutines outside Kotlin is a nightmare and probably you should not. You may convert your flow into an rxjs Observable and use those apis.

The Kotlin team already did that for the JVM, allowing to convert rxjava Observables to Flows and vice versa. You may want to do the same in JS for rxjs.

Have a look here.