eslint/no-await-in-loop Perf
作用
此规则禁止在循环体内使用 await。(for、for-in、for-of、while、do-while)。
为什么不好?
这可能表明异步操作未被有效并行化。 相反,它们是串行运行的,这可能导致性能较差。
示例
此规则错误代码的示例:
javascript
async function bad() {
for (const user of users) {
const userRecord = await getUserRecord(user);
}
}此规则正确代码的示例:
javascript
async function good() {
await Promise.all(users.map((user) => getUserRecord(user)));
}如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"rules": {
"no-await-in-loop": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
rules: {
"no-await-in-loop": "error",
},
});bash
oxlint --deny no-await-in-loop版本
该规则于 v0.3.2 中添加。
