Hi there Ludovic,
AppsScripts is certainly an interesting platform, for the reasons you mentioned. I just want to provide a bit more context, and then cover the lock service.
The server side code that is executed on google’s servers, which is often the backend of a web app, for example, is syncronous. While you can use some of the syntax and keywords of async code, such as promises and async/await, it ain’t actually async.
Where the stack is async, is in the browser. So if you have a web app with some javascript code written in an html file in the project, that is actually executed in the browser runtime.
So you could perhaps have a web app that connects with server-side appscript code that writes to the spreadsheet. The browser could be potentially doing so as the same user, by the user clicking over and over again, but writing to the spreadsheet might cause complications, such as a race condition. You therefore are logically required to make it so that a piece of code is locked, so that that same piece of code cannot be executing at the same time.
These would be separate instances of the runtime being executed at the same time, not the code itself having asyncronous features. (Important distiction to keep in mind as we reason about how the stack works.)
This is where timing comes in, because the programmer indicates to the runtime the start of the protected block of code by calling a function that will block, and only return when it’s “my turn” to start executing the protected piece of code. How long are you willing to wait until it’s your turn? It depends on the context, which the programmer has to decide.
I hope you found this educational :)
Adam
--