Linked Questions

Popular Questions

I would like to convert a callback to co-routine, and the SDK states that the API call needs to be made on the main thread. The solution works, but I am not confident that it is correct in principle.

It looks like this roughly:

   override suspend fun registerUser(email: String): ResultHandler<Profile, Exception> {

        return suspendCancellableCoroutine { continuation ->

            val observer =
                object : Observer<RegisterResponse<Profile?>> {
               fun onNext(t: Profile) {

     CoroutineScope(Dispatchers.Main).launch {
         userManager.register(email, observer)

It seems to me that the SDK wants to invoke the observer callback on the Main thread, but my process is triggered in a view model scope on the IO thread (to avoid blocking main). So the observer I guess is in practice running on the IO thread.

Thoughts on how to approach this?

Related Questions