Calling async function in main file

后端 未结 1 1544
轮回少年
轮回少年 2020-12-28 15:06

I am creating App integrating two systems. Therefore, I am using some requests and async functions. It\'s no problem to call async function in async function. However, I nee

相关标签:
1条回答
  • 2020-12-28 15:34

    Since the main scope is not async, you will need to do an async anonymous function that calls your function and itself :

    (async function() {
      await yourFunction();
    })();
    

    Or resolve the promise :

    yourFunction().then(result => {
      // ...
    }).catch(error => {
      // if you have an error
    })
    

    Hope it helps,
    Best regards

    0 讨论(0)
提交回复
热议问题