Q:

Dart waiting for an async function to complete without await

I've narrowed my problem down to the below code. I'm new to Dart, and I can't seem to figure out why the code won't move on to printing "done" before print the numbers 1-10.
import 'dart:async';

Future<bool> wait() async {
  for(int i = 0; i < 10; i++){
    print('$i');
  }
  return true;
}

Future testAsync() async {
  print('starting');
  wait();
  print('done');

}

main(List<String> arguments){
  testAsync();
}

Since there is no await keyword in front of wait(); shouldn't the program execute print('done'); and then print out the numbers? For some reason, it is waiting for wait(); to finish anyway.

A:

This is expected behavior since Dart 2.0.0:

(Breaking) Functions marked async now run synchronously until the first await statement. Previously, they would return to the event loop once at the top of the function body before any code runs (issue 30345).

https://github.com/dart-lang/sdk/blob/stable/CHANGELOG.md
Since you async method does not actually wait on anything, the entire method is therefore executed synchronously.
You can change you code into something like this to get the behavior your want:
import 'dart:async';

Future<bool> wait() async {
  await Future.microtask(() {
    for (int i = 0; i < 10; i++) {
      print('$i');
    }
  });

  return true;
}

Future testAsync() async {
  print('starting');
  wait();
  print('done');
}

main(List<String> arguments) {
  testAsync();
}

