- Run
useForLoop
independently, and observe it takes about 7 seconds to complete - Run
entrypoint
which calls useForLoop three times, asynchronously - Observe that the second run takes at least three times as long as the first run to complete
- Repeat the process above but in a browser, and observe the expected behaviour
Conclusion: Even though the documentation indicates that you can define async functions, and that you can make Promises, it ain't actually async.
Even more proof is in the fact in observing what happens when you run in the browser. It executes entrypoint()
immediately and "finishes" (although the calculations are still being made) and eventually outputs. But for the V8 engine, it indicates to the user that it is running and doesn't immediately return to the user.
- Why is
setTimeout
undefined butPromises
andAsyncFunction
work as expected (minus the actual async) - Will Google have another implementation where they do work?
Please see this gist to see the only way to do async on AppsScripts platform. (Note: It now requires you to create your own GCP project and link new project to that manually.)
I also timed it by looking at the execution logs rather than using
Logger.log
as I was wondering the same thing about calls to services; I left it in the published code for easier viewing by the end user, and I may have not noticed a difference in that case.But did you not see the
await calc()
in my code? I did have an earlier version that didn't quite have correct async code. You may have followed a link to older version?This would be correct async code: