Skip to content

Instantly share code, notes, and snippets.

@rocboronat
Last active May 7, 2021 09:56
Show Gist options
  • Save rocboronat/3ca3b89a78b073c3d1b74b43469284cc to your computer and use it in GitHub Desktop.
Save rocboronat/3ca3b89a78b073c3d1b74b43469284cc to your computer and use it in GitHub Desktop.
Play with Dart futures
void main() async {
Stopwatch stopwatch = new Stopwatch()..start();
var p1 = delay(Duration(seconds: 2));
var p2 = fetchData();
await p1;
final data = await p2;
print('Executed in ${stopwatch.elapsed} with data: $data');
}
Future delay(duration) => Future.delayed(duration);
Future<int> fetchData() => Future.value(42);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment