Reputation: 508
I have a function (function doGet()) in Google App Script that is being called from a chrome extension. This function is being called everytime a user clicks a button in chrome extension popup.html. This button in popup.html is simultaneously being clicked by 30+ users. Can I place a check that if the function is already being executed by one user, next user cannot execute it till then ?
Upvotes: 2
Views: 1309
Reputation: 3355
You can use Lock Service of App script.
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();
}
Upvotes: 3