如何在Javascript中忘记“等待”异步函数时发出警告? [英] How to warn when you forget to `await` an async function in Javascript?
本文介绍了如何在Javascript中忘记“等待”异步函数时发出警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Babel和Webpack。如果我忘记等待
异步函数,它通常会被忽视。偶尔,如果我忘了 await
,异步函数会出错,我得到一个未处理的承诺拒绝
。然后,我意识到我忘了等待
。
I'm using Babel and Webpack. If I forget to await
an async function, it can often go unnoticed. Once in a while, if I forgot the await
, an error occurs in the async function and I get an Unhandled promise rejection
. Then, I realize that I forgot the await
.
当我忘记时,有没有办法得到警告添加 await
?
Is there a way to get a warning when I forget to add an await
?
推荐答案
设置更好的eslint与webpack,repo的集成和代码编辑器。
以下是适用的规则,要求等待。
Setup better eslint integration with webpack, repo, and code editor.
Here is the applicable rule, require await.
考虑整合以下内容:
- 用于webpack级别报告的装载程序
- 用于CI / CD和本地的eslint命令行lint覆盖率
- 代码编辑器内联linting
- eslint loader for webpack-level reporting
- eslint command line for CI/CD and local lint coverage
- code editor inline linting
这篇关于如何在Javascript中忘记“等待”异步函数时发出警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文