Async support!

Good times: we can combine both synchronous and asynchronous now!

Appscript’s first runtime is synchronous, then what is async(hronous)?
Well, just imagine doing several things at once:

With asynchronous, things happen at the same time (parallel).

So appscript was originally sync?

Yes, in Appscript’s original runtime (ES5), things only happened after each other (synchronous):

TIP: Remember, synchronous code is easy to write and reason about. Therefore, a good rule of thumb is: “write synchronous code, refactor to async (when needed)".

Test async quotas?

How is async going to affect the appscript-usage quotas?

Running Promise.all() on an array with 100000 elements will definately raise some eyebrows at Google ☠

Time for a quick test:

Let’s see how appscript reacts to parallel execution (Promise.all):

Nice! In the console (CTRL+ENTER) it looks like everything worked ❤ !
I did notice that, with the original ES5 runtime, Logger.log-messages appear slightly faster in the log-window.

What’s exciting is that it just feels like running something on Node.js…without the hassle 🤓

Functions, functions..and functions

There are so many new ways to define functions now:

    function normalFunction() {}
    async function asyncFunction() {}
    function* generatorFunction() {}

    var varFunction = function() {}
    let letFunction = function() {}
    const constFunction = function() {}

    var namedVarFunction = function alternateNameVarFunction() {}
    let namedLetFunction = function alternateNameLetFunction() {}
    const namedConstFunction = function alternateNameConstFunction() {}

    var varAsyncFunction = async function() {}
    let letAsyncFunction = async function() {}
    const constAsyncFunction = async function() {}

    var namedVarAsyncFunction = async function alternateNameVarAsyncFunction() {}
    let namedLetAsyncFunction = async function alternateNameLetAsyncFunction() {}
    const namedConstAsyncFunction = async function alternateNameConstAsyncFunction() {}

    var varGeneratorFunction = function*() {}
    let letGeneratorFunction = function*() {}
    const constGeneratorFunction = function*() {}

    var namedVarGeneratorFunction = function* alternateNameVarGeneratorFunction() {}
    let namedLetGeneratorFunction = function* alternateNameLetGeneratorFunction() {}
    const namedConstGeneratorFunction = function* alternateNameConstGeneratorFunction() {}

    var varLambda = () => {}
    let letLambda = () => {}
    const constLambda = () => {}

    var varAsyncLambda = async () => {}
    let letAsyncLambda = async () => {}
    const constAsyncLambda = async () => {}

Again, the async support can be very useful. It creates lots of potential for improving the speed of old appscript-projects.

Improved logging

This is great news, now both console.log and Logger.log work with the logging screen (CTRL+ENTER).

Ohter bells and whistles

Most other things are good news too:

  • let and const
  • arrow functions () =>
  • class classes
  • Destructuring assignments {foo,bar} = data
  • template literals hello ${name}
  • default parameters function(foo=1,bar=2){..}
  • Multi-line strings

All these are not essential to write useful appscripts.
However, imagine how this could reduce the codesize of your next appscript project. Good news! ❤

Legacy projects

Well, I don’t expect much side-effects when switching runtimes..but don’t take my word for it! 😅
Here are some ideas:

This website will allow you copy/paste your old runtime code, and converts it into new runtime code

Another tip: don’t feel obliged to use the new features.
In most cases, there’s nothing wrong with writing simple code without all these bells and whistles ❤

Original article

See the original article of Google here

Further reading