Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

141
Vistas
Async/Await don't work in Google cloud functions

I work with google cloud functions and cloud messaging on Firebase. However, when I try to use Async/Await functions, I have an error: error Parsing error: Unexpected token => I work with Node.js v16.

Here is my code:

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);
    });
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Does getDeviceTokensPromise return a Promise? If so, that line should just be

const tokensSnapshot = await getDeviceTokensPromise()
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda