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

90
Vistas
Can a cloud function safely execute async work after it has returned its promise?

Can a cloud function safely execute async work after it has returned its promise? Consider the following pattern:

exports.deleteUser = functions.auth.user().onDelete(async (user) => {
    const uid = user.uid;

    asyncTask1(uid);
    asyncTask2(uid); // don't wait for the last task to finish
    asyncTask3(uid); // just attempt them all and handle
    asyncTask4(uid); // the failures individually later
    return Promise.resolve(uid);
});

async function asyncTask1(uid) {
    try {
        await someAsyncWork();
        return Promise.resolve(true);
    } catch (error) {
        throw new functions.https.HttpsError("unknown", "Task 1 failed.", error);
    }
}

Should this pattern be avoided in Cloud Functions? My concern is that the instance that was initialized to execute this call could be deallocated before the tasks have a chance to finish since the function that initialized the instance returned a promise almost immediately after being called. Or will the server keep this instance alive to let the async work finish even though the main function has already terminated?

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

0

What you are illustrating will reliably fail to work for the reason you stated. The final returned promise must resolve only after all other promises have resolved, otherwise the work might not complete. Cloud Functions doesn't do "background work" after the returned promise resolves. If you need to do continue some work without causing the function to fully terminate, you will need to pass that off to some other compute service (which you will likely also have to pay for).

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