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

Side by Side Diff: utils/pub/utils.dart

Issue 11783052: Fix chainToCompleter. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix style 2. Created 7 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | utils/tests/pub/test_pub.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /// Generic utility functions. Stuff that should possibly be in core. 5 /// Generic utility functions. Stuff that should possibly be in core.
6 library utils; 6 library utils;
7 7
8 import 'dart:async'; 8 import 'dart:async';
9 import 'dart:crypto'; 9 import 'dart:crypto';
10 import 'dart:isolate'; 10 import 'dart:isolate';
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 /// Returns a [Future] that completes in [milliseconds]. 113 /// Returns a [Future] that completes in [milliseconds].
114 Future sleep(int milliseconds) { 114 Future sleep(int milliseconds) {
115 var completer = new Completer(); 115 var completer = new Completer();
116 new Timer(milliseconds, (_) => completer.complete()); 116 new Timer(milliseconds, (_) => completer.complete());
117 return completer.future; 117 return completer.future;
118 } 118 }
119 119
120 /// Configures [future] so that its result (success or exception) is passed on 120 /// Configures [future] so that its result (success or exception) is passed on
121 /// to [completer]. 121 /// to [completer].
122 void chainToCompleter(Future future, Completer completer) { 122 void chainToCompleter(Future future, Completer completer) {
123 future 123 future.then((value) => completer.complete(value),
124 .then(completer.complete) 124 onError: (e) => completer.completeError(e.error, e.stackTrace));
125 .catchError((e) {
126 completer.completeError(e.error, e.stackTrace);
127 });
128 } 125 }
129 126
130 // TODO(nweiz): unify the following functions with the utility functions in 127 // TODO(nweiz): unify the following functions with the utility functions in
131 // pkg/http. 128 // pkg/http.
132 129
133 /// Like [String.split], but only splits on the first occurrence of the pattern. 130 /// Like [String.split], but only splits on the first occurrence of the pattern.
134 /// This will always return an array of two elements or fewer. 131 /// This will always return an array of two elements or fewer.
135 List<String> split1(String toSplit, String pattern) { 132 List<String> split1(String toSplit, String pattern) {
136 if (toSplit.isEmpty) return <String>[]; 133 if (toSplit.isEmpty) return <String>[];
137 134
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 // TODO(rnystrom): Remove this when #7781 is fixed. 187 // TODO(rnystrom): Remove this when #7781 is fixed.
191 /// When an error is rethrown in an async callback, you can end up with nested 188 /// When an error is rethrown in an async callback, you can end up with nested
192 /// AsyncErrors. This unwraps them to find the real originating error. 189 /// AsyncErrors. This unwraps them to find the real originating error.
193 getRealError(error) { 190 getRealError(error) {
194 while (error is AsyncError) { 191 while (error is AsyncError) {
195 error = error.error; 192 error = error.error;
196 } 193 }
197 194
198 return error; 195 return error;
199 } 196 }
OLDNEW
« no previous file with comments | « no previous file | utils/tests/pub/test_pub.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698