Created
June 25, 2021 11:06
-
-
Save teabyii/92d09298db403c3d620bc659d7932e16 to your computer and use it in GitHub Desktop.
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
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