Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

200
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda