johannes.lagos
01/31/2018, 9:03 PMsuspend fun requestSomething() {
return suspendableCoroutine{cont->
api.makeACall(object: Response{
fun onResponse(response: Response){
cont.resume(response)
}
fun onError(error: Error) {
cont.resumeWithException(Throwable(error.message)
}
})
}
}
And where I trigger the coroutine:
fun aMethod(){
launch(Android){
try{
requestSomething()
}catch(e: Exception) {
Timber.d("something went wrong")
}
}
}
gildor
01/31/2018, 11:31 PM