How to create asynchronous function

3,388 views
Skip to first unread message

Edward Ulle

unread,
Feb 5, 2022, 12:14:42 PM2/5/22
to Google Apps Script Community
I was looking at the async function description and it does the opposite of what I want to do.  async really makes the function run synchronously.  The next line of code is forced to wait for the previous function's Promise (if it can be queued asynchronously) to complete. 

My question is how can I create a function that would run asynchronously and the main code not wait for it to finish?

Alan Wells

unread,
Feb 5, 2022, 1:22:45 PM2/5/22
to Google Apps Script Community
You can make multiple google.script.run.functionName() calls.

google.script.run.fnk_One()
google.script.run.fnk_Two();//This line of code doesn't wait for the previous line of code to complete the run on the server

Server function two will start running regardless of whether function one has completed or not.
Both server functions will be running at the same time.
You don't need a success handler if there is no need for the client side to process a return value.
Or either one of the client side calls could have a success handler.
Does that answer your question?

Tanaike

unread,
Feb 5, 2022, 7:38:18 PM2/5/22
to Google Apps Script Community
For example, is this Google Apps Script library useful for your situation? https://github.com/tanaikech/RunAll

Edward Ulle

unread,
Feb 6, 2022, 9:02:12 AM2/6/22
to Google Apps Script Community
I'm not talking about from HTML Service but from Google App Script.

Jonathan Butler

unread,
Feb 7, 2022, 4:10:01 PM2/7/22
to google-apps-sc...@googlegroups.com
Tanaike's library does run from Google App's Script. It seems to be the best option to achieve what you are looking for.

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/ad01cdab-0547-4bd9-9a3f-4fe26ea72222n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages