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

Unified Diff: pkg/http/lib/src/utils.dart

Issue 11394003: Add an HTTP client based on Curl. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 8 years, 1 month 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
« no previous file with comments | « pkg/http/lib/src/curl_client.dart ('k') | pkg/http/test/curl_client_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/http/lib/src/utils.dart
diff --git a/pkg/http/lib/src/utils.dart b/pkg/http/lib/src/utils.dart
index 02a0f7e0fbce1dfdf3befc43ad606f4a35c21a0e..9f22351643331e52cb32cbb8145cecc820d8fa47 100644
--- a/pkg/http/lib/src/utils.dart
+++ b/pkg/http/lib/src/utils.dart
@@ -183,3 +183,26 @@ Future forEachFuture(Iterable input, Future fn(element)) {
}
return nextElement(null);
}
+
+/// Creates a temporary directory and passes its path to [fn]. Once the [Future]
+/// returned by [fn] completes, the temporary directory and all its contents
+/// will be deleted.
+Future withTempDir(Future fn(String path)) {
+ var tempDir;
+ var future = new Directory('').createTemp().chain((dir) {
+ tempDir = dir;
+ return fn(tempDir.path);
+ });
+ future.onComplete((_) => tempDir.delete(recursive: true));
+ return future;
+}
+
+/// Configures [future] so that its result (success or exception) is passed on
+/// to [completer].
+void chainToCompleter(Future future, Completer completer) {
+ future.handleException((e) {
+ completer.completeException(e);
+ return true;
+ });
+ future.then(completer.complete);
+}
« no previous file with comments | « pkg/http/lib/src/curl_client.dart ('k') | pkg/http/test/curl_client_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698