The following Google Apps Script is one example of how the Lock Service can be used to prevent concurrent running of code. Here we have a Google Form that can be submitted by users at any point, the code then takes some of those details and appends them to another Google Sheet row. In normal circumstances this will happen relatively quickly and without clashes, but what if multiple people submit the Form at the same time!?
The likelihood is that whilst the Form data will still be collected correctly in the response sheet, the append Sheet will either overwrite data as it tries to keep up or miss it completely. By using the Lock Service we can allow each Form submission time to complete its bit of code before the next one starts.
|
Lock Service code snippet
|