Synchronous

Javascript library - syncGoogleScriptRun

Overview

This is a Javascript library to use “google.script.run” with the synchronous process.

Description

When I create Web Apps, add-on using a side bar and dialog, there is the case that I want to use google.script.run with the synchronous process. As you know, google.script.run works with the asynchronous process. So in order to use it as the synchronous process, the script is required to be prepared. I also saw several issues for such situation at Stackoverflow and other sites. I thought that when the script for achieving this was prepared as a library, it might be useful for users. So I created this.

Sample Script for Executing with Synchronous Process using Node.js

Gists

This is a sample script for executing with the synchronous process using Node.js.

Sample script

function work(e) {
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            console.log(e);
            resolve("ok" + e);
        }, 1000);
    });
}

async function main() {
    var ar = [1, 2, 3, 4, 5];
    for (var i = 0; i < ar.length; i++) {
        console.log('start' + ar[i]);
        await work(ar[i]).then((res) => console.log(res));
        console.log('end' + ar[i]);
    }
}

main(); // Run main().

Result

start1
1
ok1
end1
start2
2
ok2
end2
start3
3
ok3
end3
start4
4
ok4
end4
start5
5
ok5
end5