Created
July 6, 2019 10:50
-
-
Save ryanlid/f8d59c5c08f8805c5169bdb644a2da2c to your computer and use it in GitHub Desktop.
dart async await Future (flutter)
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:io'; | |
void main() { | |
performTask(); | |
} | |
void performTask() async { | |
task1(); | |
String task2result = await task2(); | |
task3(task2result); | |
} | |
void task1() { | |
print('task 1 complete'); | |
} | |
Future task2() async { | |
Duration threeSeconds = Duration(seconds: 3); | |
String result; | |
await Future.delayed(threeSeconds, () { | |
result = 'task 2 data'; | |
print('task 2 complete'); | |
}); | |
return result; | |
} | |
void task3(String task2Data) { | |
String result = 'task 3 data'; | |
print('task 3 complete $task2Data'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment