我正在使用Coroutine launch
运行一个简单的 Retrofit 请求,并收到此错误kotlinx.coroutines.JobCancellationException: Parent job is Cancelled; job=JobImpl{Cancelled}@759d1e0
该请求在第一次尝试中有效,并在第二次尝试中返回异常。
这是我的课程:
class QuestionPresenter(
private val uiContext: CoroutineContext,
private val view: QuestionView
): BasePresenter(uiContext, view) {
val service = ApiServiceImpl()
fun getSendQuestionResponse(email: String, text: String) {
view.showProgressIndicator(true)
val job = launch(coroutineContext) {
val data = service.getRetrofit().getSendQuestionResponse()
if (data != null) {
view.getSendQuestionResponse(true)
}
}.invokeOnCompletion {
it?.let {
view.showError(it)
}
view.showProgressIndicator(false)
}
}
}
以及用于构建协程上下文的代码:
private val job = Job()
private val exceptionHandler = CoroutineExceptionHandler { _, throwable ->
baseView.showError(throwable)
}
override val coroutineContext: CoroutineContext
get() = mainContext + job + exceptionHandler
请给我一些错误的建议