Last active
April 29, 2020 05:01
-
-
Save lihourchhin/d9df54fac8e062c942ee978234bdab32 to your computer and use it in GitHub Desktop.
This file contains hidden or 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() { | |
| // performe async & await | |
| perform(); | |
| // synchronize | |
| sTask1(); | |
| sTask2(); | |
| sTask3(); | |
| // asynchronize | |
| print("run with async"); | |
| aTask1(); | |
| aTask2(); | |
| aTask3(); | |
| } | |
| void sTask1() { | |
| print("task 1"); | |
| } | |
| void sTask2() { | |
| print("task 2"); | |
| } | |
| void sTask3() { | |
| print("task 3"); | |
| } | |
| // | |
| void aTask1() { | |
| print("task 1"); | |
| } | |
| void aTask2() { | |
| Duration three = Duration(seconds: 3); | |
| Future.delayed(three, (){ | |
| print("task 2"); | |
| }); | |
| } | |
| void aTask3() { | |
| print("task 3"); | |
| } | |
| void perform () async{ | |
| print("working with Async & Await"); | |
| tTask1(); | |
| String task2result = await tTask2(); | |
| tTask3(task2result); | |
| } | |
| void tTask1(){ | |
| print("TT 1"); | |
| } | |
| Future<String> tTask2() async { //<String> will perform the Promise to this function ! | |
| Duration three = Duration(seconds: 3); | |
| String results; | |
| await Future.delayed(three, (){ | |
| results = "revieve data from Ttask2 data"; | |
| print("TT complete"); | |
| }); | |
| return results; | |
| } | |
| void tTask3(String data){ | |
| print("TT 3"); | |
| print(data); | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment