-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ktor suspend fun #214
Comments
Hello! Good question. We recently added a new module |
hi @arkivanov, i've tried coroutinesinterop from your master branch and use it in my view model:
on Android it runs fine, however on ios, i'm getting error:
it looks like the error is caught everytime i called httpclient.get in my api class
|
Yeah, coroutines do not like to be frozen in K/N because they are single threaded ATM. This is the known transitive problem in Currently you can write the following:
It should work given you are subscribing on the main thread. |
hi @arkivanov yes its working now, i need to look more into this K/N concurrency things. thanks and nice library, will definitely use it 👍 |
Thanks for the feedback! If your are working for a company, would you mind to mention its name? |
hi @arkinov, upon further checking, i'm still getting this error
after i did 2nd onnext (pull to refresh on ios)
and yes, i'm from Indonesia, i run my own consultant and software company with other 2 friends :), here's our website: thanks |
Could you please post a full stack trace? |
And subscription part as well please (where you are subscribing to this |
sure, ill post it first thing tomorrow |
hi @arkivanov , this is the full stack
This is where i implemented subscription:
this is the viewmodel class
and this is the code in kotlin multiplatform for ViewModelBinding
This is the link to my example project if you want to see the full flow :) |
There are two points:
|
hi @arkivanov, yes i've tried that before but i'm getting this exception on java and working fine on K/N
it turned out i have to use isThreadLocal = false in java and isThreadLocal = true in K/N when subscribing, is that the correct approach? because then i have to use runOnUiThread on my android view:
|
I have checked you project, let's try the following:
The crucial part is to use main context for corotuine: PS: you can keep isThreadLocal=true |
hi @arkivanov it's crash on iOS with the following error:
i ended up using
|
Makes sense. I will try to overcome this limitation in the upcoming release. Let's keep this issue open. |
|
Yep, also Job and CoroutineScope can not be frozen. Almost finished with a workaround. |
@gotamafandy After #221 you should be able to write in the following normal way:
And keep |
hi @arkivanov i've checked your latest 1.0.0 release version, i see that you did modification in Checking on android its working as expected, however on iOS i'm not getting http response 200 ok from ktor. I tried changing back to old one:
and i'm getting 200 OK response from ktor, any thoughts? |
Please check whether the coroutine is actually executed or not. Also please try version 1.0.1 and let me know the result. |
@arkivanov i'm still getting the same result with ver 1.0.1, on other topic, i just published a tutorial article on medium for kotlin multiplatform + reactive using this library, here's the link if you want to check it out: |
Could you please elaborate? Is coroutine actually executed? What about http request, does it execute? |
@CherryPerry I would appreciate your help as well with this issue. Would be nice if you check coroutine-interop with ktor on iOS. |
hi @arkivanov, yes the both coroutine and http request is executed, this is the log using the old
as you can see, i'm able to get http response 200 OK now changing back to version 1.0.1 by using:
The process stop there. (i will going to check on this deeper later) This is the part of the code to get http response
This is my view model
Note: adding .subscribeOn and observeOn will cause exception on iOS |
Thanks, we will check it as well. What I can tell now is: you should add subscribeOn and observe on, because on iOS it uses runBlocking {} which will block the UI thread. Perhaps this this why your can't get the response. Try to create HttpClient inside coroutine to avoid its freezing. |
hi @arkivanov moving httpclient to suspend fun, give me a different error:
i will take a closer look into ktor code to check it out, thanks for the help |
Make sure you have observeOn(mainThread), right after flatMap |
As I posted earlier, try the code as follows:
|
hi @arkivanov yes, i've updated the viewmodel as well before moving httpclient to coroutines |
@gotamafandy could you please provide a full stack trace of |
hi @arkivanov , this is the full stack trace
|
Alright, seems like the issue is inside |
yes, thats what i thought, havent gotten chance to check it deeper, thanks @arkivanov |
We are getting exactly the same crash |
did you find any workaround? i'm currently using the former approach (without observeOn/subscribeOn, and using the old singleFromCoroutine) |
Not really. We ended up with expect/actual with custom simple implementations for Android and iOS. And we are not using coroutines at the moment. Still using kotlinx serialization for JSON parsing. |
hi guys, this is more of a question rather than an issue, i'm trying this library to connect to API using ktor which depend on coroutines.
Let say i have http request
any suggestion how to convert into observable?
thanks guys
The text was updated successfully, but these errors were encountered: