await_only_futures
仅等待 Future。
详情
#避免在非 Future 的任何内容上使用 await。
允许在以下类型上使用 Await:Future<X>
、FutureOr<X>
、Future<X>?
、FutureOr<X>?
和 dynamic
。
此外,明确允许使用 await null
作为引入微任务延迟的一种方式。
错误示例
dart
main() async {
print(await 23);
}
正确示例
dart
main() async {
await null; // If a delay is really intended.
print(23);
}
启用
#要启用 await_only_futures
规则,请在您的 analysis_options.yaml
文件中的 linter > rules 下添加 await_only_futures
analysis_options.yaml
yaml
linter:
rules:
- await_only_futures
如果您改为使用 YAML 映射语法来配置 linter 规则,请在 linter > rules 下添加 await_only_futures: true
analysis_options.yaml
yaml
linter:
rules:
await_only_futures: true
除非另有说明,否则本网站上的文档反映的是 Dart 3.7.1 版本。页面上次更新于 2025-03-07。 查看源代码 或 报告问题。