gpt4 book ai didi

Grails promise 丢失数据 - 似乎不等待对方完成

转载 作者:行者123 更新时间:2023-12-02 15:40:51 25 4
gpt4 key购买 nike

以下随机调用getParentCustomersgetAccountManagers第一的。当它运行时,它工作正常。然而,无论哪一个被调用第二个通过 null进去。这些方法都不会以任何方式改变传入的值。我猜想这些是从指向 response.salesChannels 的原始指针调用的上下文中的某些内容。在任务之间迷路。

Map response = [
salesChannels: null,
accountManagers: null,
parentCustomers: null,
isrs: null,
operatingUnits: null,
businessUnits: null
]

def t1 = task {
response.salesChannels = salesChannelApiService.get(salesChannel)

def t1a = task {
response.parentCustomers = salesChannelTransformService.getParentCustomers(response.salesChannels)
}
def t1b = task {
response.accountManagers = salesChannelTransformService.getAccountManagers(response.salesChannels)
}

waitAll([t1a, t1b])
}

def t2 = task {
//... other stuff
}

def t3 = task {
//... other stuff
}

waitAll([t1, t2, t3])

return response

我什至尝试修改内部结构以利用 onComplete反而。
...
onComplete([task {
return salesChannelApiService.get(salesChannel)
}], { salesChannels ->
response.salesChannels = salesChannels

def t1a = task {
response.parentCustomers = salesChannelTransformService.getParentCustomers(salesChannels)
}
def t1b = task {
response.accountManagers = salesChannelTransformService.getAccountManagers(salesChannels)
}

waitAll([t1a, t1b])
})
...

但是,我仍然得到相同的结果。

注意:这也是随机的。有时它工作正常 - 将相同的列表传递给两种方法。但是,当它破裂时,总是先触发第二个。

对此有什么想法吗?

最佳答案

目前,以下解决方案正在运行。但是,我不知道为什么上述代码块都没有。

有什么想法吗?

def t1 = createPromise()

task {
response.salesChannels = salesChannelApiService.get(salesChannel)

def t1a = createPromise()
def t1b = createPromise()

task {
response.parentCustomers = salesChannelTransformService.getParentCustomers(response.salesChannels)
t1a.accept()
}
task {
response.accountManagers = salesChannelTransformService.getAccountManagers(response.salesChannels)
t1b.accept()
}

onComplete([t1a, t1b], { a, b -> t1.accept() })
}

关于Grails promise 丢失数据 - 似乎不等待对方完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61235703/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com