在Android应用中。
suspend fun getTraidersList(isCustomtHandle: Boolean = false): Any {
suspend fun execOperation() = traderMonitorRestClient.getTraidersList()
return runOperationWithoutHandle(::execOperation) // real execute here
}
suspend private fun runOperationWithoutHandle(func: suspend () -> Response<*>): Response<*> = withContext(Dispatchers.IO) {
val response: Response<*> = func() // in runtime replace by method body (e.g. traderMonitorRestClient.getTraidersList())
response
}
如您在getTraidersList
中所见,我使用了嵌套的一行功能
suspend fun execOperation() = traderMonitorRestClient.getTraidersList()
traderMonitorRestClient.getTraidersList()
的真正执行在线上
runOperationWithoutHandle(::execOperation)
问题是:
为什么traderMonitorRestClient.getTraidersList()
在声明处不执行?
suspend fun execOperation() = traderMonitorRestClient.getTraidersList()