在 Firebase 的 HTTP 函数中,我们得到:
Terminate HTTP Functions DOC link
Always end an HTTP function with send(), redirect(), or end(). Otherwise, your function might continue to run and be forcibly terminated by the system. See also Sync, Async and Promises.
问题
其他类型的函数(例如由 Firestore 事件触发的函数)是否需要类似的功能?
我是否需要返回某些内容(即使它为空)或其他命令来显式结束它?
最佳答案
Is something similar necessary to other types of functions like the ones triggered by Firestore events?
所有其他类型的云函数(即除 HTTP 云函数之外的所有云函数)都要求您返回一个 promise ,该 promise 将在异步工作完成时解决。这包括后台触发的云函数(例如由 Firestore 事件触发的函数)。
如果您的云函数不包含异步操作,您可以在所有工作完成后返回一个简单的值,例如 null
。如果您想要取消 Cloud Function 执行,例如未满足先决条件,您也可以执行此操作。官方 Cloud Functions 示例显示了几个示例,特别是 here一个here .
我建议您观看 Firebase 视频系列中有关“JavaScript Promises”的 3 个视频:https://firebase.google.com/docs/functions/video-series/其中详细解释了这一点。
关于node.js - 我是否需要明确由 Firestore 事件触发的 "end"Firebase Cloud Functions?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59561961/