The problem isn’t with the batch. The problem is that your larger Cloud Functions code doesn’t return a promise that resolves when all the async work is complete (see the documentation on that). In fact, for the main if (newUsername !== oldUsername)
block, your code returns nothing at all, and that’s a problem.
Minimally, you code should go more like this:
if (newUsername !== oldUsername) {
// ...
const promiseA = conversationQueryA.get()
// ...
const promiseB = conversationQueryB.get()
// ...
return Promise.all([promiseA, promiseB])
}
else {
return null
}
Now it will return a value no matter which primary code path is taken, and it will return a promise that resolves only after both chains of async work are complete.
CLICK HERE to find out more related problems solutions.