美文网首页
await async

await async

作者: 糖醋里脊120625 | 来源:发表于2020-07-29 14:17 被阅读0次
    function resolveAfter2Seconds() {
      return new Promise(resolve => {
        setTimeout(() => {
          resolve('resolved');
        }, 2000);
      });
    }
    
    async function asyncCall() {
      console.log('calling');
      const result = await resolveAfter2Seconds();
      console.log(result);
      // expected output: "resolved"
    }
    
    asyncCall();
    

    相关文章

      网友评论

          本文标题:await async

          本文链接:https://www.haomeiwen.com/subject/nlvhrktx.html