如果您等待其响应,为什么还要使用异步功能呢?
为什么我们使用异步函数,如果我们将等待它们的响应进行等待,在这种情况下,Syncronus函数有什么区别?
Why we using async function if then we use await for waiting their response, in this case what's the difference between a syncronus function?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下是使用异步/等待的比较,然后:
异步函数允许您使用等待 +使函数返回承诺( https://developer.mozilla.org/fr/docs/web/javascript/reference/reference/global_objects/promise )
如您所见'。同时函数打印“ end”,然后一旦解决了对API的请求,则打印结果。
为了简化,等待“等待答案,然后执行代码的其余部分”,然后表示“收到响应时...”然后执行,然后执行代码结束
Here is a comparison between using async / await and then :
async function allow you to use await + make the function return a promise (https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/Promise)
As you can see, await block the function execution and wait for the result before printing 'End'. While syncronious function print 'End' then print the result once the request to the api is resolved.
To simplify, await means "wait for the answer then execute the rest of the code" while then means "when you receive the response do ..." then it execute then end of the code