我在Firebase上使用google云功能和云消息。然而,当我尝试使用Async/Await函数时,我有一个错误:error Parsing error: Unexpected token =>
我使用Node.js v16.
const functions = require("firebase-functions");
// const mess = require("firebase/messaging");
const admin = require("firebase-admin");
exports.sendListenerPushNotificationProductUpdate = functions.database
.ref("Products/{product}/type/")
.onUpdate(async (snapshot, context) => {
...
const tokensSnapshot = await Promise.resolve(getDeviceTokensPromise);
console.log("TOKEN: " + JSON.stringify(tokensSnapshot));
// Check if there are any device tokens.
if (!tokensSnapshot.hasChildren()) {
return functions.logger.log(
"There are no notification tokens to send to."
);
}
...
// Listing all tokens as an array.
const tokens = Object.keys(tokensSnapshot.val());
// Send notifications to all tokens.
const response = await admin.messaging().sendToDevice(tokens, payload);
// For each message check if there was an error.
const tokensToRemove = [];
return Promise.all(tokensToRemove);
});
getDeviceTokensPromise
是否返回Promise
?如果是,那一行应该是
const tokensSnapshot = await getDeviceTokensPromise()