Daniel Möller
Daniel Möller

Reputation: 86650

Google LockService doesn't seem to work at all

I'm trying to use the LockService class. But it doesn't seem to work at all!!

I have a button in a sheet (a drawing, in fact) that calls a method.

And at the beginnng of that method I have:

var Lock = LockService.getScriptLock();
var TryLock = Lock.tryLock(5000);
Browser.msgBox(TryLock.toString());
if (!TryLock)
{
  return;
}

Browser.msgBox("Haslock " + Lock.hasLock().toString());

//script's body, nothing related to Locks
//everything related to the current (and only) document

Lock.releaseLock();

So, in first place, TryLock is ALWAYS true! No matter how many times I press the button to run two, three or ten scripts at once. (The script is long enough to take about one minute).

And second, hasLock is ALWAYS false! That is completely against the documentation.

Am I missing something?

Upvotes: 1

Views: 430

Answers (1)

BHT Auto
BHT Auto

Reputation: 11

Actually, the reason is the UI-object (Browser.msgBox()) drops the lock. Avoid or move the UI objects to reach concurrency.

var Lock = LockService.getScriptLock();
var TryLock = Lock.tryLock(10000);

Logger.log(Lock.hasLock()); // true
Logger.log(Lock.hasLock()); // true
  
Browser.msgBox(Lock.hasLock()); // true
Browser.msgBox(Lock.hasLock()); // false

Upvotes: 1

Related Questions