Continue execution after sending response (Cloud Functions for Firebase)

前端 未结 3 686
醉话见心
醉话见心 2020-11-27 21:56

I\'m using Firebase Functions with https triggers, and I was wondering how long after sending the response to the client, the functions keeps executing. I want to send a res

3条回答
  •  再見小時候
    2020-11-27 22:19

    You should expect that the HTTP function terminates the moment after you send the response. Any other behavior is some combination of luck or a race condition. Don't write code that depends on luck.

    If you need to send a response to the client before the work is fully complete, you will need to kick off a second function to continue where the HTTP function left off. It's common to use a pub/sub function to do with. Have the HTTP function send a pub/sub message to another function, then terminate the HTTP function (by sending a response) only after the message is sent.

提交回复
热议问题