Skip to content

Instantly share code, notes, and snippets.

@ericgrandt
Created May 6, 2019 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericgrandt/f30ae96a17de307b8dc0dcb022ba62ed to your computer and use it in GitHub Desktop.
Save ericgrandt/f30ae96a17de307b8dc0dcb022ba62ed to your computer and use it in GitHub Desktop.
// With asynchronous operations
import 'dart:async';
main() {
longOperation();
printSomething();
}
Future<void> longOperation() async {
var retVal = await runLongOperation();
print(retVal);
}
const retString = 'Waited 3 seconds to return this without blocking execution.';
Duration delay = Duration(seconds: 3);
Future<String> runLongOperation() => Future.delayed(delay, () => retString);
printSomething() {
print('I printed right away!');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment