Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

77
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!