I have written code for newer Node version which I wish to implement as Google Cloud Function (GCF). Now issue is that GCF only offers Node v6.14.0 engine which does not support Async functions.
Solution that I liked was to use https://www.npmjs.com/package/asyncawait given that I won't need to do major changes (also same applies when I later wish to use the native async once newer Node is available). However, I am unable to run my code even though I believe I have followed the examples in my conversions correctly.
I either get error "xx is not a function" if I declare the function as per the instructions or if I declare the function differently (which I think should work) I get "xx is not defined".
Below are two play snippets that produce the errors. Number 1) is as per instructions in the npm website and number 2) the alternative.
Number 1) as per the instructions -> "printStuff is not a function" error
var async = require('asyncawait/async');
var await = require('asyncawait/await');
printStuff()
var printStuff = async (function () {
var files = await (console.log("x"));
var files2 = await (console.log("y"));
return
});
Number 2) the alternative -> "printStuff is not defined" error (I have also tried adding more brackets to be in line with the example here - half way down the page which uses the same package - SyntaxError: Unexpected token function - Async Await Nodejs)
var async = require('asyncawait/async');
var await = require('asyncawait/await');
printStuff();
async (function printStuff() {
var files = await (console.log("x"));
var files2 = await (console.log("y"));
return
});
Any help would be appreciated!
Thank you!!