Created
February 21, 2023 09:40
-
-
Save mhmadip/8c31e61d5870e877a26a71234dad8627 to your computer and use it in GitHub Desktop.
This example for OOP2 class, showing how async functions are working on Dart
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(){ | |
performTasks(); | |
} | |
void performTasks () async{ | |
task1(); | |
String task2Result= await task2(); | |
task3(task2Result); | |
} | |
void task1(){ | |
String result='task 1 data'; | |
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 with $task2Data'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment