Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Latest commit

 

History

History
23 lines (21 loc) · 915 Bytes

UnawaitedFutures.md

File metadata and controls

23 lines (21 loc) · 915 Bytes

Forgetting to await a future (in expression statements) seems to be a common cause of errors / test flakiness.

The scissors/src/checker/transformer transformer warns against unawaited futures in async method bodies, with a couple of hard-coded special cases (see README for usage).

Examples (given Future fut();):

  foo()       { fut(); }           // OK: assuming fire-and-forget semantics.
                                   //     Could consider a hint here.
  foo() async { fut(); }           // Warning
  foo() async { await fut(); }     // OK
  foo() async { var x = fut(); }   // OK
  foo() async {
    new Future.delayed(d);         // Warning
    new Future.delayed(d, bar);    // OK: special case
  }
  foo() async {
    var map = <String, Future>{};
    map.putIfAbsent('foo', fut()); // OK: special case
  }