Is it possible to call Lock in two unrelated functions without locking affecting the other?

If I have two unrelated functions in Code.gs

(each interacting with a different google sheet), can I call lock

in both functions without one call acting on the other?

For future reference, an application that has about 80 users within the same domain works like Me, however, it is possible that:

  • User A calls myFunction_01()

    at the same time
  • User B calls myFunction_02()

In this case, will the locks work independently?

Is the following implementation possible lock

?

function myFunction_01() {

var my_spreadsheet_01 = SpreadsheetApp.openById("YYY");

var lock = LockService.getScriptLock();

try {
  lock.waitLock(30000); 
} catch (e) {
    Logger.log('Could not obtain lock after 30 seconds.');
    var returnObjectCatchError = {};
    returnObjectCatchError['LockErrorFlag'] = "An exception occurred when waiting for lock"; 
    return returnObjectCatchError; 
}

// do things with my_spreadsheet_01 here

var return_object = {};

// apply all pending spreadsheet changes
SpreadsheetApp.flush(); 

//release lock
lock.releaseLock();

return return_object;

}

function myFunction_02() {

var my_spreadsheet_02 = SpreadsheetApp.openById("ZZZ");

var lock = LockService.getScriptLock();

try {
  lock.waitLock(30000); 
} catch (e) {
    Logger.log('Could not obtain lock after 30 seconds.');
    var returnObjectCatchError = {};
    returnObjectCatchError['LockErrorFlag'] = "An exception occurred when waiting for lock"; 
    return returnObjectCatchError; 
}

// do things with my_spreadsheet_02 here

var return_object = {};

// apply all pending spreadsheet changes
SpreadsheetApp.flush(); 

//release lock
lock.releaseLock();

return return_object;

}

      

+3
locking google-apps-script


source to share


No one has answered this question yet

See similar questions:

2
Lack of LockService

or similar:

170
Recursive locking (Mutex) versus non-recursive locking (Mutex)
4
How do I understand the LockService and implement it correctly?
1
Calling the function result returns "undefined"
1
Open the lock correctly in try clauses
1
Google Apps script how to remove a trigger from another project
1
calling flock inside a function always "succeeds", ignoring the previous lock
0
How can I grant access to this buffer using CSingleLock?
0
Is this code blocking the onFormSubmit (e) method correctly?
0
How to get / read email id from response



All Articles
Loading...
X
Show
Funny
Dev
Pics