question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

suspend fun getUser(): User {
return user
}

any suggestion how to convert into observable?

subject
.subscribeOn(ioScheduler)
.flatMapSingle { service.getUser() } -> here we're getting result from suspend fun
.observeOn(mainScheduler)

thanks guys

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:36 (20 by maintainers)

github_iconTop GitHub Comments

1reaction
arkivanovcommented, Oct 6, 2019

@gotamafandy After #221 you should be able to write in the following normal way:

        result = mStartProperty
            .doOnBeforeNext { loadingProperty.onNext(true) }
            .flatMapSingle {
                singleFromCoroutine { useCase.execute(it) }
                    .susbcribeOn(ioScheduler)
            }
            .flatMap {
                when (it) {
                    is Result.Success -> {
                        observableOf(it.response)
                    }
                    else -> observableOfEmpty()
                }
            }
            .observeOn(mainScheduler)
            .doOnBeforeNext {
                loadingProperty.onNext(false)
            }

And keep isThreadLocal=true in the bindings.

1reaction
arkivanovcommented, Oct 3, 2019

Makes sense. I will try to overcome this limitation in the upcoming release. Let’s keep this issue open.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Proper way to call a suspended function in ktor - Stack Overflow
i would like to start a process is active while my ktor server is up. suspend fun doWork(){ while(true){ delay(2000L) printit("I did work")...
Read more >
Understanding suspend function of Kotlin Coroutines - Medium
When we talk about coroutine, Suspend Functions are like its backbone. So it is very important to know what it is ... private...
Read more >
Creating a client application - Ktor
In the next step, we'll make our main function suspending to fix this issue. Click the red bulb and choose Make main suspend....
Read more >
Composing Coroutines and Suspend Functions - Baeldung
In this tutorial, we'll look into various types of coroutines we might want to create in our application and how to compose them...
Read more >
How to use call.respond in non-suspended function. #101
I am using ktor 0.3.2 with netty, kotlin1.1 and Java8. ... inline suspend fun ApplicationCall.respond(message: Any) { ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found