oxen-io / session-android

A private messenger for Android.
https://getsession.org
GNU General Public License v3.0
1.73k stars 165 forks source link

Correct the usage of flowOn #1508

Closed simophin closed 1 week ago

simophin commented 4 weeks ago

Description

flowOn applies to operators BEFORE not after.

simophin commented 4 weeks ago

Cool! Alternatively, I think the function we were looking for was collectOn which operates on the downstream. Perhaps we could replace it with that?

either way:

1. Does using `flowOn` on the merged flow allow for parallelism?

2. Did you check for any other usages of `flowOn` in the app, or is this home screen only?

3. Did you put a log or breakpoint in the offending function(s) to check they're not on main? I guess we could even call one of those `assertNotMainThread()` kinda methods if we really wanted. or even `if (BuildConfig.DEBUG) assertNotMain()` or `assertNotMainIfDebug()` if we use it frequently and want a shorthand.

I was looking for something like collectOn as well but couldn't find such thing. I did put breakpoint on the db acess AFTER the changes and they all ran on background threads.

bemusementpark commented 4 weeks ago

Nice, does it run concurrently with one flowOn after a merge/combine? or should we add appropriate scheduling to each flow?

simophin commented 4 weeks ago

Nice, does it run concurrently with one flowOn after a merge/combine? or should we add appropriate scheduling to each flow?

Yes they do, just confirmed in the debugger that they run concurrently in different threads as expected. My understanding is that Dispatchers.IO is a thread pool facility so the behavior should be along the line of "apply this dispatcher to the operators == apply this thread pool to this operators"