employee.php:219 Uncaught SyntaxError: await is only valid in async function code example
Example 1: Uncaught SyntaxError: await is only valid in async function
const sleep = (n) => new Promise((res) => setTimeout(res, n));
const arr = [1, 2, 3];
const asyncRes = await arr.reduce(ASYNC (memo, e) => {
await sleep(10);
return (await memo) + e;
}, 0);
console.log(asyncRes);
Example 2: await is only valid in async function
async function start() {
....
const result = await helper.myfunction('test', 'test');
}