Skip to content

Instantly share code, notes, and snippets.

@Wassmd
Created September 24, 2019 12:32
Show Gist options
  • Save Wassmd/5296059e4b363e88ffe3d779a86551d7 to your computer and use it in GitHub Desktop.
Save Wassmd/5296059e4b363e88ffe3d779a86551d7 to your computer and use it in GitHub Desktop.
Async programming with Dart
import 'dart:io';
void main() {
performTasks();
}
void performTasks() async {
task1();
String output = await task2();
task3(output);
}
void task1() {
String result = "Task1 performed";
DateTime dateTime = DateTime.now();
print('$dateTime $result');
}
Future task2() async {
Duration threeSeconds = Duration(seconds: 3);
//sleep(duration);
String result;
await Future.delayed(threeSeconds, () {
result = "Task2 result";
DateTime dateTime = DateTime.now();
print('$dateTime Task2 is complete and result is prepared');
});
return result;
}
void task3(String resultOfTask2) {
String result = "Task3 performed";
DateTime dateTime = DateTime.now();
print('$dateTime $result with $resultOfTask2');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment