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
Using async/await inside firebase cloud functions

When performing asynchronous tasks inside a firebase cloud function do I need to await for every task like the example below:

exports.function = functions.https.onCall(data,context)=>{
await db.doc('someCollection/someDoc').update({someField: 'someValue'})
await db.doc('someCollection/someDoc2').update({someField: 'someValue'})
await db.doc('someCollection/someDoc3').update({someField: 'someValue'})
return {}
}

or can I just fire these asynchronous calls? given that I don't need to return anything based on the data received from these tasks to the client like in the other example below:

exports.function = functions.https.onCall(data,context)=>{
 db.doc('someCollection/someDoc').update({someField: 'someValue'})
 db.doc('someCollection/someDoc2').update({someField: 'someValue'})
 db.doc('someCollection/someDoc3').update({someField: 'someValue'})
return {}
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Yes, you need to wait for all asynchronous work to complete as part of executing your function. Async work will very likely not complete on its own if you don't return a promise that resolves when all the work is done (which async functions do when you use await correctly).

The documentation states:

To return data after an asynchronous operation, return a promise. The data returned by the promise is sent back to the client.

One thing that was missing from your first code sample is the async keyword that would make await work correctly:

exports.function = functions.https.onCall(async (data,context) => {
    db.doc('someCollection/someDoc').update({someField: 'someValue'})
    db.doc('someCollection/someDoc2').update({someField: 'someValue'})
    db.doc('someCollection/someDoc3').update({someField: 'someValue'})
    return {}
}
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