sange93 / MVPDemo

Retrofit+OkHttp+Kotlin协程 网络请求MVP架构
11 stars 4 forks source link

RetrofitManagerKt 类中request方法有错误 #1

Open xuningForAndroid opened 4 years ago

xuningForAndroid commented 4 years ago

deferred.await(),提示suspension functions can be called only within coroutine body,不能通过编译,请问什么原因

sange93 commented 4 years ago

挂起函数  只能在 协程范围内调用

---原始邮件--- 发件人: "xuningForAndroid"<notifications@github.com> 发送时间: 2020年5月28日(周四) 晚上6:34 收件人: "sange93/MVPDemo"<MVPDemo@noreply.github.com>; 抄送: "Subscribed"<subscribed@noreply.github.com>; 主题: [sange93/MVPDemo] RetrofitManagerKt 类中request方法有错误 (#1)

deferred.await(),提示suspension functions can be called only within coroutine body,不能通过编译,请问什么原因

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

xuningForAndroid commented 4 years ago

那这应该怎么写? image

xuningForAndroid commented 4 years ago

/**

sange93 commented 4 years ago

你的Presenter文件,有没有从Activity 把协程域传递给Presenter?

sange93 commented 4 years ago

参考下: class AddressListPresenter(scope: CoroutineScope) : BasePresenterKt(), CoroutineScope by scope, AddressListContract.Presenter {

override fun deleteAddress(id: String, position: Int) = launch {
    val map = HashMap<String, Any>()
    map["id"] = id
    RetrofitManagerKt.request(RetrofitManagerKt.apiService.requestAsync(map), true, mContext)?.also {
        if (it.code == 0) {
            mView?.deleteAddressSuccess(position)
        } else {
            ToastUtils.showShort(it.message)
        }
    }
}

} ———————————————— 版权声明:本文为CSDN博主「小石头93」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/sange77/article/details/102575852