Хорошо, я вижу вашу проблему здесь и исправьте меня, если я ошибаюсь, ваш текущий формат выглядит следующим образом:
exports.updateFeeds = functions.firestore
.document('feedItems/{feedID}')
.onUpdate((change, context) => {
return somePromise.get().then(returnData=>{
dosomethingwith(returnData);
return anotherpromise.get().then(anotherreturndata=>{
dosomethingwith(anotherreturndata);
})
})
});
Этот стиль написания обещаний потерпит неудачу, потому что вы не должны вкладывать свои обещания какчто.
Это должно выглядеть примерно так:
exports.updateFeeds = functions.firestore
.document('feedItems/{feedID}')
.onUpdate((change, context) => {
return somePromise.get()//initial return function its return value is passed to returnData
.then(returnData=>{//now we have the value that was returned from the function above
return dosomethingwith(returnData);//do something with the data from somePromise.get()
}).then(somethingWasDoneWithReturnData=>{ //this is the result of the dosomethingwith function because we returned it
return anotherPromiseFunction.get();// now we need to return another promise
}).then(returnFromAnotherPromiseFunction=>{//the result from anotherPromiseFunction gets passed into the block below this doSomeThingWith(returnFromAnotherPromiseFunction);
doSomeThingWith(returnFromAnotherPromiseFunction);
})
});
Вот часть моего кода от одной из моих функций firebase, которые обращают адреса геокодов.
return orderRef.get().then(doc=>{
let order = doc.data();
return order;
}).then(order=> getAddresses(order.rectangles))
.then(allAddresses=> eliminateDuplicates(allAddresses))
.then(duplicateAddressesRemoved=> batchReverseGeocode(duplicateAddressesRemoved))
.then(reverseGeocodedAddresses=> {
allAddresses = reverseGeocodedAddresses;
newAddressCount = allAddresses.length;
newChargeTotal = calculatePrice(newAddressCount);
console.log(allAddresses);
console.log(newAddressCount);
return writeFirebase(addressStorageRef, {addresses: reverseGeocodedAddresses}, null)
})
.then(noneObject=> updateFirebase(chargeRef, {status: "Charge Completed", finalChargeAmount: newChargeTotal, finalAddressCount: newAddressCount}, null))
.then(noneObject=> updateFirebase(orderRef, {status: "Paid In Full", finalChargeAmount: newChargeTotal, finalAddressCount: newAddressCount}, null))
.then(noneObject=>{
//now we need to update the charge and move on
return stripe.charges.capture(stripeChargeID, {amount: newChargeTotal})
});