dave08
09/15/2017, 10:30 AMelizarov
09/15/2017, 1:04 PMdave08
09/15/2017, 2:15 PMelizarov
09/15/2017, 2:23 PMdave08
09/15/2017, 2:26 PMsubscribeOn(RxKotlin.coroutineIO())
dave08
09/15/2017, 2:28 PMnapperley
09/16/2017, 4:00 AMelizarov
09/16/2017, 6:22 AMdave08
09/17/2017, 11:49 AMnapperley
09/18/2017, 4:11 AMelizarov
09/18/2017, 7:53 AMkotlinx-coroutines-rx1
was not meant as a replacement for Rx at all. It augments Rx with ability to iterate over reactive streams from coroutines, which enables you to encode complex business logic easily and directly.dave08
09/18/2017, 11:26 AMdave08
09/18/2017, 11:30 AMkotlinx-coroutines-rx1
should replace rx, but rather leverage the existing rxjava Schedulers model that along with the possibility to use thread pools when needed, it should be able to 'schedule' operations to coroutines... I don't know if that's possible...elizarov
09/18/2017, 12:54 PMfun Scheduler.asCoroutineDispatcher()
that converts Rx scheduler into coroutine dispatcher.elizarov
09/18/2017, 12:54 PMdave08
09/18/2017, 12:57 PMdave08
09/18/2017, 12:58 PMelizarov
09/18/2017, 12:58 PMkotlinx-coroutines-rx
and write this code in a simpler way, while still using all your Rx schedulers.elizarov
09/18/2017, 1:00 PMdave08
09/18/2017, 1:04 PMservice.getUsers()
.map(::mapJsonToUser)
.subscribeOn(Scheduler.asCoroutineDispatcher())
.subscribe(subscriber)
And not have to write ::mapJsonToUser as suspend fun nor have getUsers be suspend fun, and the coroutines-rx Scheduler will automatically run them as coroutines?dave08
09/18/2017, 1:50 PMelizarov
09/18/2017, 2:37 PMsubscribeOn(coroutineDispatcher)
. You subscribe on Rx scheduler.elizarov
09/18/2017, 2:37 PMdave08
09/18/2017, 2:38 PMdave08
09/18/2017, 2:39 PMelizarov
09/18/2017, 2:40 PMelizarov
09/18/2017, 2:41 PMdave08
09/18/2017, 2:45 PMsuspend fun mapJsonToUser(..):..
, then how would I use asCoroutineDispatcher
?dave08
09/18/2017, 3:19 PMsuspend fun
?elizarov
09/18/2017, 3:21 PMfun foo(): Observable<T>
that returns a Ts and suspend fun bar(item: T)
that does some complex async stuff on T and you want to invoke bar
on each item from foo
, so you do launch(context) { foo().consumeEach { bar(it) } }
and it just works.elizarov
09/18/2017, 3:22 PMmap
, then the map itself will suspend.dave08
09/18/2017, 3:24 PMdave08
09/18/2017, 3:25 PMlaunch(context) { foo().consumeEach { bar(it) } }
actually subscribes to the observable?elizarov
09/18/2017, 4:04 PMconsumeEach
doeselizarov
09/18/2017, 4:05 PMelizarov
09/18/2017, 4:05 PMdave08
09/18/2017, 4:08 PMelizarov
09/18/2017, 4:09 PMelizarov
09/18/2017, 4:09 PMelizarov
09/18/2017, 4:09 PMdave08
09/18/2017, 4:10 PMelizarov
09/18/2017, 4:10 PMelizarov
09/18/2017, 4:10 PMelizarov
09/18/2017, 4:11 PMcontext
dave08
09/18/2017, 4:11 PMelizarov
09/18/2017, 4:12 PMlaunch(UI) { myObservable.consumeEach { updateUI(it) } }
elizarov
09/18/2017, 4:13 PMif (condition) doOneAsyncAction() else doOtherAsyncAction()
. This kind of logic is non-trivial to express with Rx combinatorsdave08
09/18/2017, 4:15 PMmyObservable
is doing some kind of network request, it can't be run as suspendable, it has to run on an rx scheduler.. just the result gets run as a coroutine...dave08
09/18/2017, 4:16 PMmyObservable
has to be rewritten as a suspend fun
, and then ditch rx...dave08
09/18/2017, 4:17 PMelizarov
09/18/2017, 4:28 PMelizarov
09/18/2017, 4:29 PMelizarov
09/18/2017, 4:30 PMdave08
09/18/2017, 4:30 PMelizarov
09/18/2017, 4:31 PMelizarov
09/18/2017, 4:32 PMdave08
09/18/2017, 4:32 PMelizarov
09/18/2017, 4:33 PMcomsumeEach
. It provides conversion.dave08
09/18/2017, 4:33 PMelizarov
09/18/2017, 4:33 PMelizarov
09/18/2017, 4:33 PMdave08
09/18/2017, 4:34 PMdave08
09/18/2017, 4:34 PMelizarov
09/18/2017, 4:34 PMdave08
09/18/2017, 4:35 PMelizarov
09/18/2017, 4:35 PMelizarov
09/18/2017, 4:35 PMdave08
09/18/2017, 4:36 PMelizarov
09/18/2017, 4:36 PMelizarov
09/18/2017, 4:36 PMelizarov
09/18/2017, 4:37 PMdave08
09/18/2017, 4:37 PMelizarov
09/18/2017, 4:38 PMdave08
09/18/2017, 4:38 PMdave08
09/18/2017, 4:38 PMelizarov
09/18/2017, 4:38 PMelizarov
09/18/2017, 4:38 PMelizarov
09/18/2017, 4:39 PMdave08
09/18/2017, 4:39 PMdave08
09/18/2017, 4:39 PMelizarov
09/18/2017, 4:40 PMdave08
09/18/2017, 4:41 PMelizarov
09/18/2017, 4:44 PMdave08
09/18/2017, 4:47 PM