我有一个类似于下面的函数。当用户提交应用程序时触发。与其他用户寻找合适的匹配。如果它找不到匹配的,我希望它在10秒后再次检查。我希望它调用函数"deleteReference(gameid)“。此函数也将再次检查。如果没有其他用户与之匹配,引用将被删除。
在一些问题中,他们谈论的是一个有延迟的解决方案,但是他们等待的时间是有报酬的。如何在10秒后触发我想要的函数(通过发送gameID变量)?最能负担得起的费用。
exports.myFunction = functions.database.ref('/match/{gameid}/').onCreate((snapshot, context) => {
//do some processing here
if (matchResult == true) {
return null;
} else {
// HOW CAN I CALL THIS FUNCTION AFTER 10 SEC ?
deleteReference(gameid)
return null;
}
});
function deleteReference(gameid) {
//do some processing here
if (matchResult == false) {
database.ref("/match/").child(gameid).remove();
}
}发布于 2022-06-28 05:52:04
一种选择是使用Cloud (由@samthecodingman链接)。您还可以使用setTimeout()来延迟deleteReference()函数的执行。见下面的示例代码:
exports.myFunction = functions.database.ref('/match/{gameid}/').onCreate((snapshot, context) => {
//do some processing here
if (matchResult == true) {
return null;
} else {
// Execute the function after 10 seconds
setTimeout(deleteReference(gameid), 10000)
return null;
}
});
function deleteReference(gameid) {
//do some processing here
if (matchResult == false) {
database.ref("/match/").child(gameid).remove();
}
}https://stackoverflow.com/questions/72780175
复制相似问题