延迟谷歌云功能 [英] Delay Google Cloud Function

查看:31
本文介绍了延迟谷歌云功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个与 Google Firebase 配对的 swift iPhone 应用程序.在应用程序中,用户将完成一个动作(按下一个按钮).此时,我想安排一个 Google Firebase 函数在用户操作后 45 分钟运行.但是,我希望能够在 iPhone 应用程序中完成另一个操作(按下按钮)时取消此功能.我可以使用计时器在 swift 内快速执行此操作,但如果用户关闭应用程序,这将不起作用.

I have a swift iPhone application paired with Google Firebase. Within the application the user will complete an action (press a button). At this point, I would like to schedule a Google Firebase Function to run 45 minutes after the user action. However, I would like this function to be able to be cancelled when another action (press a button) is completed within the iPhone application. I could do this within swift with a timer but that wouldn't work if the user closes the application.

我不反对使用第三方调度程序或类似的东西.欢迎提出任何建议.

I am not opposed to using a third party scheduler or something of the sorts. Any suggestion welcome.

我查看了可能重复的问题和答案(Cloud Functions for Firebase准时触发?)但是,该答案中的大多数链接已被弃用且已过时.此外,这指的是重复安排一些事情.例如,每小时一次、每天一次等...我希望在触发(用户操作)后 45 分钟安排作业,并能够在该 45 分钟窗口内取消作业.

I have looked at the possible duplicate questions and answers (Cloud Functions for Firebase trigger on time?) However, most of the links in that answer are deprecated and out of date. Also, that is referring to scheduling something repeatedly. For example, every hour, once a day, etc... I am looking to schedule the job 45 minutes after trigger (user action) with the ability to cancel the job within that 45 minute window.

推荐答案

Javascript/Typescript 允许你使用 setTimeout 函数进行延迟

Javascript/Typescript allows you to delay using the setTimeout function

// time is in milliseconds
function delay(time:number) {
  return new Promise(res => {
    setTimeout(() => {
      res("VALUE TO RESOLVE");
    }, time);
  });
}

然后通过执行 const res = await delay(1000);

这篇关于延迟谷歌云功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆