在此Kotlin代码中:
async {
lateinit var testResult: TestResult
val startTime = Date()
try {
withContext(Dispatchers.IO) {
unitTest.getTestToRunAsync()?.invoke { result ->
testResult = result
doOnTestCompleted(testInfo, testResult, startTime, Date())
}
}
} catch (exception: Exception) {
testResult = TestResult("Exception: ${exception.message}")
}
}
我想调用doOnTestCompleted,其定义如下:
private suspend fun doOnTestCompleted(
testInfo: TestInfo,
testResult: TestResult,
startTime: Date,
endTime: Date,
copyTestResults: Boolean = true
) {
}
但是我不能调用doOnTestCompleted,因为从其调用的lambda主体不是协程。 getTestToRunAsync的定义是:
fun getTestToRunAsync(): (suspend (testToRunAsync: (resultCallback: TestResult) -> Unit) -> Unit)? {
return this.testToRunAsync
}
我怎么称呼doOnTestCompleted?