https://kotlinlang.org logo
#coroutines
Title
# coroutines
j

johannes.lagos

01/31/2018, 9:03 PM
Copy code
suspend 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:
Copy code
fun aMethod(){
      launch(Android){
     try{
      requestSomething()
}catch(e: Exception) {
  Timber.d("something went wrong")
}
}
}
g

gildor

01/31/2018, 11:31 PM
Why do you use such low level API for coroutines. Don't what is you library for requests, but looks that you can easily write much more high level one with support of cancellation for example
3 Views