目錄

await_only_futures

僅等待 futures。

此規則自 Dart 2.0 起可用。

規則集:corerecommendedflutter

此規則有快速修正可用。

詳細資訊

#

避免在非 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