函数返回名称不以 async 结尾的 Deferred

nic*_*net 2 kotlin kotlinx.coroutines

我最近正在尝试学习 Kotlin 协程,我注意到在返回一堆asyncIDE的地图的情况下,显示消息说Function returning Deferred with a name that does not end with async. 这是我的代码

runBlocking {
    try {
        val siteDeferred = async { getSite(order) }
        // Place where I get warning-----------| (Function returning Deferred with a name that does not end with Async)
        //                                     v
        val orderLineDeferred = order.line.map { async { getOrderDetail(it) } }

        // Place where I get warning-------------------| (Function returning Deferred with a name that does not end with Async)
        //                                             v
        val orderLineProductsDeferred = order.line.map { async { getOrderProductInformation(it.productId) } }

        val site = siteDeferred.await()
        val orderLine = orderLineDeferred.awaitAll()
        val orderLineProducts = orderLineProductsDeferred.awaitAll()
    } catch (e: Throwable) {
        throw Exception(e.message)
    }
}

private suspend getOrderDetail(OrderLine orderLine): OrderDetail...
private suspend getSite(Order order): Site ...
private suspend getOrderProductInformation(String productId): Product ...
Run Code Online (Sandbox Code Playgroud)

我在这里错过了什么吗?此外,我想知道这是否是进行异常处理的正确方法,有没有办法清理try块,以便我可以直接获取值,即使这意味着我必须async在其他方法中使用。

小智 5

函数getSite()重命名为getSiteAsync() ?其他函数以这种方式修改。