Last active
January 29, 2024 03:14
-
-
Save doyle-flutter/ba5e8bcdc57d385bb7d88ce5a6f99578 to your computer and use it in GitHub Desktop.
class01 future
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(){ | |
void a() => print("a"); | |
void b(){ | |
DateTime start = DateTime.now(); | |
DateTime now = start; | |
while(now.difference(start).inSeconds < 5) { | |
now = DateTime.now(); | |
} | |
print("b"); | |
} | |
void c() => print("c"); | |
// // (1) | |
// a(); | |
// b(); // 5초 동안 대기 -> 모든 프로세스 대기 | |
// c(); | |
Future<void> b2() async{ | |
await Future.delayed(Duration(seconds: 5)); | |
print("b2"); | |
} | |
// // (2) | |
// a(); | |
// b2(); // 5초 동안 대기 -> 단독 대기 | |
// c(); | |
// // (3) | |
// Future(() async{ | |
// a(); | |
// await b2(); // 5초 대기 -> 흐름 중 대기 a -> b(5s) -> c | |
// c(); | |
// }); | |
// // (3-2) | |
Future<void> play() async{ | |
a(); | |
await b2(); | |
c(); | |
} | |
print("play start"); | |
play(); // 5초 대기 -> 흐름 중 대기 a -> b(5s) -> c | |
print("play end"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment