Skip to content

Instantly share code, notes, and snippets.

@DaleLaw
Created June 25, 2018 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DaleLaw/7ce664fac6bd162619e9c7153c66d292 to your computer and use it in GitHub Desktop.
Save DaleLaw/7ce664fac6bd162619e9c7153c66d292 to your computer and use it in GitHub Desktop.
Wrapping Okhttp with RxJava
object RxOkhttp {
private val client = OkHttpClient()
operator fun get(request: Request): Observable<Response> {
return Observable.defer(Callable<ObservableSource<out Response>> {
try {
val response = client.newCall(request).execute()
return@Callable Observable.just(response)
} catch (e: IOException) {
return@Callable Observable.error<Response>(e)
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment