Created
February 11, 2017 07:51
-
-
Save kilink/3bb7d52050492831b618931fc9b786a8 to your computer and use it in GitHub Desktop.
This file contains 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
import java.io.IOException | |
import okhttp3.Call | |
import okhttp3.Callback | |
import okhttp3.Response | |
import rx.Single | |
fun Call.toSingle(): Single<Response> = | |
Single.create { subscriber -> | |
enqueue(object : Callback { | |
override fun onResponse(call: Call, response: Response) { | |
if (!subscriber.isUnsubscribed) { | |
subscriber.onSuccess(response) | |
} | |
} | |
override fun onFailure(call: Call, e: IOException) { | |
if (!subscriber.isUnsubscribed) { | |
subscriber.onError(e) | |
} | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment