hey guys, can we use `RxKotlin` in `Kotlin-Native`...
# kotlin-native
b
hey guys, can we use
RxKotlin
in
Kotlin-Native
common module?
s
If you are referring to https://github.com/ReactiveX/RxKotlin then no, you cannot. RxKotlin wraps RxJava, which is Java code. However https://github.com/Kotlin/kotlinx.coroutines can be used in place of RxJava / RxKotlin in some instances, but is still different. There is a plan to add cold streams, which will be conceptually similar to RxJava streams, to the kotlin coroutines library. You can track that work on this issue: https://github.com/Kotlin/kotlinx.coroutines/issues/254
b
got it, thanks 🙂
s
I should also mention that the coroutines library has not released support yet for kotlin/native. It's actively being worked on currently.
b
s
You could prototype something using that approach, but I wouldn't release something to production until the release of native coroutines via Kotlin's library. I believe that approach has a race condition.
b
yeah, that might be the case.
better to follow Kotlinconf-app like completion callback approach
k
I'm currently working on a much dumbed down implementation of LiveData. This is just to get something out for the near term. It works as a multiplatform typealias to android and a simplified version on iOS. Can open that up sooner if there are interested parties who want to poke around with it.
👍 1
d
@bipin there were requests/talks last year about MPP support for RxKotlin https://github.com/ReactiveX/RxKotlin/issues/115 . Not sure if that went anywhere though.
g
better to follow Kotlinconf-app like completion callback approach
You can use coroutines for this case even without kotlinx.coroutines, if you just want to use them as callbacks with nice syntax. Check this sample: https://github.com/JetBrains/kotlin-native/blob/master/samples/nonBlockingEchoServer/src/main/kotlin/EchoServer.kt
👍 1
You can see non-blocking implementation of echo server with sockets. Callbacks wrapped to coroutines
Minute of speculations. I think kotlinx.coroutines will be standard de facto of async library for multiplatform Kotlin libraries. I do not believe that we will see pure Kotlin multiplatform implementation of Rx soot, at least production ready and with complete set of features. It’s pretty big project that should compete with kotlinx.coroutines maintained by JB and already strong community. it will be especially doubtful when kotlinx.coroutines will introduce cold streams. Would be much easier to write any required Rx operator as library for this cold streams abstraction rather than write Rx implementation from the scratch or even using Kotlinx.Coroutines under the hood.
b
thanks @drofwarcs @gildor , Still bit curious how can we use coroutine implementation on iOS too. I am basically building cross-platform app for Android and iOS.
g
For now you can just use suspend functions to wrap async api on both platforms, but no threading, no high level primitives
it’s just a way to use callbacks-like API as coroutines
b
yeah, i am looking like that, don’t want to make code bit complex in my first app, mainly want to avoid platform dependent compilation issue too 😉
ah, you mean like this:
fun acceptClientsAndRun(serverFd: Int, block: suspend Client.() -> Unit) {
g
No
I mean something like:
Copy code
suspend fun doSomethingAsyncronous(): Result
instead of something like:
Copy code
fun doSomethingAsyncronous(onSuccess: (Result) -> Unit, onError: (Throwable) -> Unit)
b
👍