我部署了以下云功能:
exports.onUserNameUpdated = functions.database.ref('users/{uid}/userName').onUpdate(event => {
if (event.data.previous.val() === event.data.val()) {
return;
}
const uid = event.data.ref.key();
const p1 = root.child(`/userlist/${uid}`).set(event.data.val());
root.child(`following/${key}/list`).once('value').then(snapshot => {
var followingPromises = [];
snapshot.forEach(child => {
const uid2 = child.val().uid;
const promise = rootRef.child(`followers/${uid2}/list/${key}/userName`).set(event.data.val());
followingPromises.push(promise);
});
return Promises.all(followingPromises);
}).catch(reason => {
console.log(reason);
});
root.child(`followers/${key}/list`).once('value').then(snapshot => {
var followerPromises = [];
snapshot.forEach(child => {
const uid2 = child.val().uid;
const promise = root.child(`following/${uid2}/list/${key}/userName`).set(event.data.val());
followerPromises.push(promise);
});
return Promises.all(followerPromises);
}).catch(reason => {
console.log(reason);
});
return p1;
});
部署后,我在终端收到以下警告:
warning Arrow function expected no return value consistent-return
这是函数的最后一行,返回p1;。为什么没有预期返回的承诺?
答案 0 :(得分:0)
我会说你在这里有几个承诺“晃来晃去”而没有被考虑到最终归还的承诺,应该在所有工作完成后解决。每次调用set()和once()及其promise链都需要在终止函数之前完全解析。