purna
06/19/2018, 11:10 AMsuspend fun methodName(image: Bitmap?): String? = async {
// heavy task
}.await()
OR
fun methodName(image: Bitmap?): String? {
//heavyTask
}
and in Code
async{
methodName()
}.await()
gildor
06/19/2018, 1:30 PMval IO = newFixedThreadPoolContext(POOL_SIZE, "IoDispatcher")
suspend fun methodName() = withContext (IO) {
//Heavy work
}
But don't forget that in many cases you cannot cancel "blocking heavy work", so be careful with this
If "hevy work" is some async work, so do not blocking thread, just use suspend function without additional wrapper with custom context,