await is only valid in async function
async function start() {
....
const result = await helper.myfunction('test', 'test');
}
await is only valid in async function
async function start() {
....
const result = await helper.myfunction('test', 'test');
}
Uncaught SyntaxError: await is only valid in async function
//If you are using reduce(), the since the result of the first accumulation loop
//will be used in the second second loop.so need one more asyc in front of
// reduce parameters:
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);
// 6
//
SyntaxError: await is only valid in async function
// My function
const myfunction = async function(x, y) {
return [
x,
y,
];
}
// Start function
const start = async function(a, b) {
const result = await myfunction('test', 'test');
console.log(result);
}
// Call start
start();
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us