我在 Google App 脚本中有一个函数(函数 doGet()),它是从 Chrome 扩展程序调用的。每次用户单击 chrome 扩展 popup.html 中的按钮时都会调用此函数。 popup.html 中的此按钮同时被 30 多个用户点击。我可以检查一下,如果该函数已经由一个用户执行,那么下一个用户在此之前无法执行它吗?
最佳答案
您可以使用Lock Service应用程序脚本。
The Lock Service allows scripts to prevents concurrent access to sections of code. This can be useful when you have multiple users or processes modifying a shared resource and want to prevent collisions.
function doGet(){
var lock = LockService.getScriptLock();
lock.waitLock(10000); // in milliseconds
// Your code
lock.releaseLock();
}
关于google-apps-script - 如何检查 Google App Script 中的函数是否已被其他用户执行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45816748/