Hi there! I have already tried asking in RX channe...
# ktor
j
Hi there! I have already tried asking in RX channel, but nobody responded. I am trying to call an Observable pipeline from a Ktor request handler. The problem is that response writer is already closed before Observable produces a result, how do I go about this?
r
Do have to use an Observable, or could you switch to coroutines-only? If you need to use an observable, you'll have to bridge that into coroutines, by using the
suspendCoroutine
function from the ktor request handler, and resume the coroutine inside that once the observable completes. Something like this (from memory, so might not be completely correct):
Copy code
val observable: Observable
val observableResult = suspendCoroutine { continuation ->
    observable.subscribe { it -> continuation.resume(it) }
}
j
I have to use Observable because the API I am attempting to use is based on RxJava. Unless I am misunderstanding somehow and there is a way of transforming RX operators into coroutines?
r
No there are no standard operators, you'll have to do what I explained then, use
suspendCoroutine
to bridge the two worlds 🙂
j
Thanks, this seems to work!