Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(385)

Unified Diff: sdk/lib/_internal/pub/bin/pub.dart

Issue 521643005: Convert more pub code to use async/await. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revise! Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/pub/bin/pub.dart
diff --git a/sdk/lib/_internal/pub/bin/pub.dart b/sdk/lib/_internal/pub/bin/pub.dart
index 8f7fa4e32ddb192e82476c190c4953617b49973d..a608f1187fecc040d4288e699493c0be3a2df2aa 100644
--- a/sdk/lib/_internal/pub/bin/pub.dart
+++ b/sdk/lib/_internal/pub/bin/pub.dart
@@ -129,7 +129,7 @@ int chooseExitCode(exception) {
}
/// Walks the command tree and runs the selected pub command.
-Future invokeCommand(String cacheDir, ArgResults mainOptions) {
+Future invokeCommand(String cacheDir, ArgResults mainOptions) async {
var commands = PubCommand.mainCommands;
var command;
var commandString = "pub";
@@ -174,26 +174,23 @@ Future invokeCommand(String cacheDir, ArgResults mainOptions) {
'Command "${options.name}" does not take any arguments.');
}
- return syncFuture(() {
- return command.run(cacheDir, mainOptions, options);
- }).whenComplete(() {
+ try {
+ await command.run(cacheDir, mainOptions, options);
+ } finally {
command.cache.deleteTempDir();
- });
+ }
}
/// Checks that pub is running on a supported platform.
///
/// If it isn't, it prints an error message and exits. Completes when the
/// validation is done.
-Future validatePlatform() {
- return syncFuture(() {
- if (Platform.operatingSystem != 'windows') return null;
-
- return runProcess('ver', []).then((result) {
- if (result.stdout.join('\n').contains('XP')) {
- log.error('Sorry, but pub is not supported on Windows XP.');
- return flushThenExit(exit_codes.USAGE);
- }
- });
- });
+Future validatePlatform() async {
+ if (Platform.operatingSystem != 'windows') return;
+
+ var result = await runProcess('ver', []);
+ if (result.stdout.join('\n').contains('XP')) {
+ log.error('Sorry, but pub is not supported on Windows XP.');
+ return flushThenExit(exit_codes.USAGE);
nweiz 2014/08/29 23:30:41 "return" -> "await"
Bob Nystrom 2014/09/03 23:44:16 Done.
+ }
}

Powered by Google App Engine
This is Rietveld 408576698