Skip to content

Instantly share code, notes, and snippets.

@samramez
Created March 15, 2020 16:13
Show Gist options
  • Save samramez/017e03341e5d3dfdaf159898fc4eabe7 to your computer and use it in GitHub Desktop.
Save samramez/017e03341e5d3dfdaf159898fc4eabe7 to your computer and use it in GitHub Desktop.
Simple practice code for using Dart Future object.
import 'dart:async';
void main() {
Future<int>.delayed(Duration(seconds: 3), () {
return 100;
}).then((value) {
print(value);
}).then((value) {
throw Exception();
}).catchError((exception) {
print("exception happened");
}).whenComplete(() {
print("everything is now complete!");
}).then((value) {
print("I get printed after everything was completed :)");
});
print("waiting..");
}
@samramez
Copy link
Author

In order to test this sample code, just go to https://dartpad.dev/ and copy-paste all the code from this Gist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment