google apps script - Lock Service getScriptLock() does it work in libraries -
I am creating a script library which will be used by several other scripts. These scripts will run together and I need to control access to a resource, access to a spreadsheet.
The documentation is not entirely clear to me. Example LockService.getPublicLock ();
refers to the method. I have created a library to test LockService
in which there is a method that receives a lock:
This.doTest = function (testClient ) {Var lock = LockService.getScriptLock (), success;
try {lock.waitLock (1000); Logger.log (testClient + 'received lock'); Utilities.sleep (2000); Lock.releaseLock (); } Hold (e) {Logger.log (testclient + 'lock could not be obtained after 2 seconds'.); } }
The test library is used in two other test scripts. If I run test scripts, then both scripts sometimes fail to get a lock. This is what I want to see.
But the example in the documentation refers to another method and the library has been used in various scripts, I would like to ensure that this is what it is supposed to do to work.
The question is whether the script lock works in the entire library and it will lock the code segment without using the library in separate scripts. And are there any other issues that I should be worried about?
I believe you are right in your assumption: the lock instance used in the library The script will be shared by everyone, at least this script is using my library.
If you look at it, and scroll down to the shared and non-shared resources table, you will see that lock is an non-shared resource , Which has been explained as table footnote
This means that the library has its own example of the resource / feature and that all the scripts that share the library and that Access to the same frequency
The grave of that section If rather confusing, I should say, with the 'share' and 'non-shared' concepts not explained very well. But the essence of this is: Unless your lock is created in the library code, all the scripts using that library will take the same example of the lock.
Comments
Post a Comment