1. 内联函数
1.2 案例分析
open class BaseRepository {
suspend inline fun <reified T : Any> launchRequest(
crossinline block: suspend () -> CResponse<T>,
noinline onSuccess: ((T?) -> Unit)? = null,
noinline onError: ((Exception)-> Unit) ? = null,
noinline onComplete: (() -> Unit)? = null ){
try {
val response = block()
onSuccess?.invoke(response?.data)
} catch (e: Exception) {
e.printStackTrace()
when (e) {
is UnknownHostException -> {
}
is ConnectException -> {
}
else -> {
}
}
onError?.invoke(e)
}finally {
onComplete?.invoke()
}
}
}


2. 协程
2.1 初入门-稀土掘金系列文章
添加链接描述
