Last active
May 7, 2021 09:56
-
-
Save rocboronat/3ca3b89a78b073c3d1b74b43469284cc to your computer and use it in GitHub Desktop.
Play with Dart futures
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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