Created
June 25, 2018 15:10
-
-
Save DaleLaw/7ce664fac6bd162619e9c7153c66d292 to your computer and use it in GitHub Desktop.
Wrapping Okhttp with RxJava
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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