Skip to content

Instantly share code, notes, and snippets.

@cankush625
Created August 11, 2020 09:54
Show Gist options
  • Select an option

  • Save cankush625/7b2fd754727dfe8e61fc975b2f176ccd to your computer and use it in GitHub Desktop.

Select an option

Save cankush625/7b2fd754727dfe8e61fc975b2f176ccd to your computer and use it in GitHub Desktop.
Asynchronous programming in dart
void main() => myTasks();
myTasks() {
printMessage();
acknowledgeFileUpload();
thankyouMessage();
}
void printMessage() {
print("Task Started");
}
Future<int> uploadFileToTheServer() async {
print("Uploading file...");
Duration d = new Duration(seconds: 10);
await Future.delayed(d);
return 1;
}
void acknowledgeFileUpload() {
Future<int> result = uploadFileToTheServer();
String res = result.toString();
if (res.compareTo("1") == 1) {
print("success");
} else {
print("failed");
}
}
void thankyouMessage() {
print("Thanks for using this platform");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment