Skip to content

Instantly share code, notes, and snippets.

@teabyii
Created June 25, 2021 11:06
Show Gist options
  • Save teabyii/92d09298db403c3d620bc659d7932e16 to your computer and use it in GitHub Desktop.
Save teabyii/92d09298db403c3d620bc659d7932e16 to your computer and use it in GitHub Desktop.
import "dart:async";
void main() {
run();
}
Future<void> run() async {
int count = 0;
final timer = Timer.periodic(Duration(seconds:1), (timer) {
print(count++);
});
// 我们常用的
// await fakeRequest1();
// await fakeRequest2();
// 应该这么写
final a = fakeRequest1();
final b = fakeRequest2();
await a;
await b;
timer.cancel();
}
Future<void> fakeRequest1() async {
await Future.delayed(Duration(seconds: 5));
}
Future<void> fakeRequest2() async {
await Future.delayed(Duration(seconds: 3));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment