我正在尝试在后端调用中实现异步,我一直在阅读,似乎 GParse 是一个很好的库来实现这一点,但我不清楚如何以正确的方式实现这一点。谁能帮我?这是我的例子:
def itemsResults
def locationResults
def itemsNearLocation
GParsPool.withPool {
itemsResults = {searchMyItems()}.async().call()
locationResults = {getLocations()}.async().call()
itemsNearLocation = {getItemsNear(locationResults)}.async().call() // i need locationresults answer in order to call this service
}
model.putAll(["items": itemsResults,
"itemsNearLocation":itemsNearLocation])
return "myView"
所以,我需要调用 2 个 api 调用,然后在第三个调用中,我需要使用之前称为 async 的响应之一,最后将其添加到我的模型中。我怎样才能做到这一点?