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

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

Issue 12213092: Rework Timer interface. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 10 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 | « utils/pub/io.dart ('k') | utils/testrunner/pipeline_utils.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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 /// This is also used to wrap synchronous code that may thrown an exception to 151 /// This is also used to wrap synchronous code that may thrown an exception to
152 /// ensure that methods that have both sync and async code only report errors 152 /// ensure that methods that have both sync and async code only report errors
153 /// asynchronously. 153 /// asynchronously.
154 Future defer(callback()) { 154 Future defer(callback()) {
155 return new Future.immediate(null).then((_) => callback()); 155 return new Future.immediate(null).then((_) => callback());
156 } 156 }
157 157
158 /// Returns a [Future] that completes in [milliseconds]. 158 /// Returns a [Future] that completes in [milliseconds].
159 Future sleep(int milliseconds) { 159 Future sleep(int milliseconds) {
160 var completer = new Completer(); 160 var completer = new Completer();
161 new Timer(milliseconds, (_) => completer.complete()); 161 new Timer(new Duration(milliseconds: milliseconds), completer.complete);
162 return completer.future; 162 return completer.future;
163 } 163 }
164 164
165 /// Configures [future] so that its result (success or exception) is passed on 165 /// Configures [future] so that its result (success or exception) is passed on
166 /// to [completer]. 166 /// to [completer].
167 void chainToCompleter(Future future, Completer completer) { 167 void chainToCompleter(Future future, Completer completer) {
168 future.then((value) => completer.complete(value), 168 future.then((value) => completer.complete(value),
169 onError: (e) => completer.completeError(e.error, e.stackTrace)); 169 onError: (e) => completer.completeError(e.error, e.stackTrace));
170 } 170 }
171 171
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 324
325 /// Add all key/value pairs from [source] to [destination], overwriting any 325 /// Add all key/value pairs from [source] to [destination], overwriting any
326 /// pre-existing values. 326 /// pre-existing values.
327 void mapAddAll(Map destination, Map source) => 327 void mapAddAll(Map destination, Map source) =>
328 source.forEach((key, value) => destination[key] = value); 328 source.forEach((key, value) => destination[key] = value);
329 329
330 /// Decodes a URL-encoded string. Unlike [decodeUriComponent], this includes 330 /// Decodes a URL-encoded string. Unlike [decodeUriComponent], this includes
331 /// replacing `+` with ` `. 331 /// replacing `+` with ` `.
332 String urlDecode(String encoded) => 332 String urlDecode(String encoded) =>
333 decodeUriComponent(encoded.replaceAll("+", " ")); 333 decodeUriComponent(encoded.replaceAll("+", " "));
OLDNEW
« no previous file with comments | « utils/pub/io.dart ('k') | utils/testrunner/pipeline_utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698