在我的Android应用中
import kotlinx.coroutines.*
import retrofit2.Response
import java.util.*
fun executeTraderOperation(traderOperation: Trader.Operation, base: String, quote: String): Response<Void> {
lateinit var executeOperations: Response<Void>
GlobalScope.launch(Dispatchers.IO) {
executeOperations = async { runOperation(traderOperation, base, quote) }
}
return executeOperations
}
suspend fun runOperation(traderOperation: Trader.Operation, base: String, quote: String): Response<Void> {
val traderMonitorRestClient = RestClientFactory.createRestClient(TraderMonitorRestClient::class.java)
val sender = BuildConfig.APPLICATION_ID + "_" + BuildConfig.VERSION_NAME
val key = DateUtil.getDateAsString(Date(), "mmHHddMMyyyy")
val executeTraderOperation = traderMonitorRestClient.executeTraderOperation(traderOperation.toString().toLowerCase(), base.trim(), quote.trim(), sender, key)
val response = executeTraderOperation.await()
return response
}
但是在这一行中我得到编译错误:
executeOperations = async { runOperation(traderOperation, base, quote) }
错误消息:
Type inference failed. Expected type mismatch:
required:
Response<Void>
found:
Deferred<Response<Void>>
答案 0 :(得分:0)
async
返回该Deffered
,将其删除并将其转换为:
async{
val executions = runOperation(traderOperation, base, quote)
}