1async function start() {
2 ....
3
4 const result = await helper.myfunction('test', 'test');
5}
1//If you are using reduce(), the since the result of the first accumulation loop
2//will be used in the second second loop.so need one more asyc in front of
3// reduce parameters:
4
5const sleep = (n) => new Promise((res) => setTimeout(res, n));
6
7const arr = [1, 2, 3];
8
9const asyncRes = await arr.reduce(ASYNC (memo, e) => {
10 await sleep(10);
11 return (await memo) + e;
12}, 0);
13
14console.log(asyncRes);
15// 6
16//
1// My function
2const myfunction = async function(x, y) {
3 return [
4 x,
5 y,
6 ];
7}
8
9// Start function
10const start = async function(a, b) {
11 const result = await myfunction('test', 'test');
12
13 console.log(result);
14}
15
16// Call start
17start();