0

我将 Ktor 用于 KMM,并希望从异步函数中获取响应,但我收到以下错误:

Cannot pass function of type '() async -> Void' to parameter expecting synchronous function type

据我所知,Kotlin 只能在主线程上运行挂起函数

func fetchData() {
        DispatchQueue.main.async {
            let t = Task{() -> String in
                do{
                    let response :String = try await KtorEngine().fetchMoods(id: id, token: token).content.readUTF8Line(limit: 333333333)!
                    return  response
                }
            }
            var res = await t.result!
        }
    }
4

0 回答 0