In an onWrite handler, I'd like to perform multiple reads, manipulate some data, and then store it. I'm fairly new to the Promise concept. Am I safe with the following Promise handling, in regards to Firebase not killing my queries before they're done?
exports.test = functions.database.ref('/zzz/{uid}').onWrite(event => {
console.log('zzz', event.data.val());
return Promise.all([
admin.database().ref('/zzz/1').once('value'),
admin.database().ref('/zzz/2').once('value')
]).then(function(snaps) {
console.log('loaded', snaps[0].val());
var updKeys = {
["/xxx/" +event.params.uid +"/zoo"]: 'giraffe',
}
admin.database().ref().update(updKeys, function(error) {
console.log("Updating data finished. ", error || "Success.");
})
});
});
The above works, but not sure its the right way...