AI-generated Key Takeaways
-
The Lock service in Apps Script helps prevent conflicts when multiple users or processes access shared resources.
-
It provides different types of locks: Document Lock, Script Lock, and User Lock, each controlling access at various levels.
-
Locks can be acquired, released, and checked for status using methods like
tryLock
,releaseLock
, andhasLock
. -
Timeouts can be set while acquiring locks to avoid indefinite waiting using methods like
tryLock
andwaitLock
.
This service allows scripts to prevent 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.
Classes
Name | Brief description |
---|---|
Lock | A representation of a mutual-exclusion lock. |
Lock | Prevents concurrent access to sections of code. |
Lock
Methods
Method | Return type | Brief description |
---|---|---|
has | Boolean | Returns true if the lock was acquired. |
release | void | Releases the lock, allowing other processes waiting on the lock to continue. |
try | Boolean | Attempts to acquire the lock, timing out after the provided number of milliseconds. |
wait | void | Attempts to acquire the lock, timing out with an exception after the provided number of milliseconds. |
LockService
Methods
Method | Return type | Brief description |
---|---|---|
get | Lock | Gets a lock that prevents any user of the current document from concurrently running a section of code. |
get | Lock | Gets a lock that prevents any user from concurrently running a section of code. |
get | Lock | Gets a lock that prevents the current user from concurrently running a section of code. |