我有两个要同时运行的函数,但我不能让它们单独运行,因为一个函数包含一个无限循环while(true)。JavaScript 的问题是,如果你在哪里运行两个函数,它会在运行下一个之前完成该函数的运行;所以如果我用while(true)循环运行一个函数,它永远不会移动到下一个函数。
如果你还不明白,这是我的代码:
function onOpen(){ // Google Apps Script trigger
infLoop() //how to run both of these functions at the same time?
runScript()
}
function infLoop(){ //inf loop.
while(True){
Utilities.sleep(100)
DocumentApp.getActiveDocument()
.setname("dont change this name")
}
}
function runScript(){
//code...
}
Run Code Online (Sandbox Code Playgroud) asynchronous function simultaneous infinite-loop google-apps-script