可能这是一个简单的问题,但我不知道该怎么做。我想从Firebase Cloud Functions中的另一个函数调用一个函数。
exports.firstFunction = functions.https.onCall((params, context) => {
return new Promise((resolve, reject) => {
return secondFunction() // how can I call secondFunction?
.then((resp) => resolve(resp))
.catch((e) => reject(e));
});
});
exports.secondFunction = functions.https.onCall((params, context) => {
return new Promise((resolve, reject) => {
return resolve("secondFunction");
});
});
使httpCallable("secondFunction")
返回正确的字符串。如果我这样做,httpCallable("firstFunction")
我有一个[Error: INTERNAL]
。
我怎样才能做到这一点?
看一看:
exports.firstFunction = functions.https.onCall((params, context) => {
return new Promise((resolve, reject) => {
return secondFunctionHandler()
.then((resp) => resolve(resp))
.catch((e) => reject(e));
});
});
const secondFunctionHandler = (params, context) => {
return new Promise((resolve, reject) => {
return resolve("secondFunction");
});
};
exports.secondFunction = functions.https.onCall(secondFunctionHandler);
我喜欢将所有云功能分成“处理程序”(在单独的文件中编写,然后导入)和索引文件中的单行,而不仅仅是我要重用的那些。它发现它使代码更具可读性和可管理性。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句