在Google Apps脚本中设置超时 [英] Set Timeout in Google Apps Scripts

查看:77
本文介绍了在Google Apps脚本中设置超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以调用 setTimeout 或等价于Google Apps脚本中的功能?

Is it possible to call setTimeout or an equivalent function in Google Apps Scripts?

当我尝试运行以下代码时:

When I try to run the following code:

function onSubmit() {
  // we've been called, remove trigger, set timeout, re-enable, and then run function
  destroySubmitHandler();
  setTimeout(function() {
    createSubmitHandler();
    myFunction()
  }, 5 * 1000)
}

我收到以下错误:

推荐答案

显然,您可以使用

Apparently you can use the function Utilities.sleep() like this:

function onSubmit() {
  // we've been called, remove trigger, set timeout, re-enable, and then run function
  destroySubmitHandler();
  Utilities.sleep(5 * 1000)
  createSubmitHandler();
  myFunction()
}

这篇关于在Google Apps脚本中设置超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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