johannes.lagos
08/23/2017, 7:18 AMawait()
on my coroutine doesn't wait to be done before it continue.gildor
08/23/2017, 7:23 AMjohannes.lagos
08/23/2017, 8:02 AMsuspend fun ServiceHelper.getList(): ListOfWishes {
return suspendCancellableCoroutine { continuation ->
getAllLists(object : ResponseReceiver<ListOfWishes> {
override fun onResponse(response: Response<ListOfWishes>?) {
continuation.resume(response?.data!!)
}
override fun onError(response: Response<ErrorList>?) {
val throwable = Throwable(Util.getFirstErrorSafe(response?.data))
continuation.resumeWithException(throwable)
}
}, RequestUtils.generateUniqueRequestId(), false, null, object : OnRequestListener {
override fun beforeRequest() {}
override fun afterRequestBeforeResponse() {}
override fun afterRequest(isDataSynced: Boolean) {}
})
}
}
johannes.lagos
08/23/2017, 8:02 AMsuspend fun ServiceHelper.wishLists(): Deferred<ListOfWishes> {
return async(CommonPool){
getWishList()
}
}
johannes.lagos
08/23/2017, 8:03 AMfun getUpdatedLists(): ListOfWishes?{
val context = Injector.getContext()
val serviceHelper = Util.getContentServiceHelper(context)
var list = ListOfWishLists()
launch(Android){
try {
list = serviceHelper.wishLists().await()
}catch (ex: Exception){
Timber.d("Error: $ex")
}
}
return list
johannes.lagos
08/23/2017, 8:03 AMgetUpdatedList
is my interop method with old java legacy codejohannes.lagos
08/23/2017, 8:05 AMfun getUpdatedList(): ListOfWishes? = runBlocking{}
I experience that it will block the main thread, and the coroutine never reach continuation.resume()
gildor
08/23/2017, 8:21 AMgildor
08/23/2017, 8:21 AMgildor
08/23/2017, 8:22 AMgildor
08/23/2017, 8:22 AMgildor
08/23/2017, 8:23 AMjohannes.lagos
08/23/2017, 8:28 AMjohannes.lagos
08/23/2017, 8:28 AMjohannes.lagos
08/23/2017, 11:01 AMgildor
08/23/2017, 11:03 AMgildor
08/23/2017, 11:04 AMjohannes.lagos
08/23/2017, 11:04 AMgildor
08/23/2017, 11:05 AMgildor
08/23/2017, 11:07 AMgildor
08/23/2017, 11:08 AM