首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >防火墙云功能运行10秒后

防火墙云功能运行10秒后
EN

Stack Overflow用户
提问于 2022-06-28 02:38:37
回答 1查看 146关注 0票数 1

我有一个类似于下面的函数。当用户提交应用程序时触发。与其他用户寻找合适的匹配。如果它找不到匹配的,我希望它在10秒后再次检查。我希望它调用函数"deleteReference(gameid)“。此函数也将再次检查。如果没有其他用户与之匹配,引用将被删除。

在一些问题中,他们谈论的是一个有延迟的解决方案,但是他们等待的时间是有报酬的。如何在10秒后触发我想要的函数(通过发送gameID变量)?最能负担得起的费用。

代码语言:javascript
复制
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();
    }
}
EN

回答 1

Stack Overflow用户

发布于 2022-06-28 05:52:04

一种选择是使用Cloud (由@samthecodingman链接)。您还可以使用setTimeout()来延迟deleteReference()函数的执行。见下面的示例代码:

代码语言:javascript
复制
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();
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72780175

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档