Does anyone know library/extension that wraps okht...
# rx
h
Does anyone know library/extension that wraps okhttp3 into Observable/Single? I need specifically okhttp3, not Retrofit.
m
probably there isn’t, but it’s really easy to do it yourself, like this
Copy code
val call: Call
Observable.fromPublisher<Response> { s ->
    call.enqueue(object : Callback {
        override fun onFailure(call: Call?, e: IOException?) = {
            s.onError(e)
        }
        override fun onResponse(call: Call?, response: Response?) = {
            s.onNext(response)
            s.onComplete()
        }

    })
}
d
But it doesn't cancel the call on .dispose()
d
check the source code for retrofit, it should be doing exactly what you're looking for
can just emulate their strategy