跳至主要內容

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