I have been following the documentation provided by Grails about promises: https://docs.grails.org/2.3.x/guide/async.html#promises
I have a huge list of ids which I'm splitting up into different tasks and then calling waitAll() on the promise list. Based on that, is it possible to rollback all the changes when one of the concurrent tasks throws an exception?
It might be easier to look at the code:
def promistList = []
def collatedList = hugeList.collate(100)
collatedList.each {
promiseList << task {
DomainObject.withTransaction {
def domainObject = findById('test')
// do more work
domainObject.save()
}
}
}
waitAll(promiseList)
This works great when everything works perfectly, but of course, I have to prepare for when things don't turn out so well. Ideally, I would like to rollback all of the changes made in all of the tasks even if the last task throws an exception.
Is this possible?