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

201
Vistas
Which function will be called a second time when a firebase transcation fails the first time?

The Firebase documentation claims:

A function calling a transaction (transaction function) might run more than once if a concurrent edit affects a document that the transaction reads.

It is unclear exactly which function will run twice when there is a concurrent edit. In the example below, outerFunc calls the runTranscation method, so a literal interpretation of the documentation would imply that that outerFunc may be called twice.

However, this seems like a strange implementation, and I suspect that the docs mean to say that innerFunc may be called more than once when there is a concurrent edit.

import { runTransaction } from "firebase/firestore";

function outerFunc () {
  console.log('outerFunction');
  try {
    await runTransaction(db, async function innerFunc(transaction) {
      const sfDoc = await transaction.get(sfDocRef);
      if (!sfDoc.exists()) {
        throw "Document does not exist!";
      }

      const newPopulation = sfDoc.data().population + 1;
      transaction.update(sfDocRef, { population: newPopulation });
    });
    console.log("Transaction successfully committed!");
  } catch (e) {
    console.log("Transaction failed: ", e);
  }
}

Could outerFunc be called twice when there is a concurrent edit as the doc imply?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

There's no way the Firestore SDK can invoke your outerFunc (let alone multiple times), but your innerFunc callback may be called multiple times by the Firestore SDK indeed.

If you find the documentation confusing, please file feedback on the page itself. There should be a link for that at the bottom right.

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