Skip to content

Instantly share code, notes, and snippets.

@lihourchhin
Last active April 29, 2020 05:01
Show Gist options
  • Select an option

  • Save lihourchhin/d9df54fac8e062c942ee978234bdab32 to your computer and use it in GitHub Desktop.

Select an option

Save lihourchhin/d9df54fac8e062c942ee978234bdab32 to your computer and use it in GitHub Desktop.
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