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

Side by Side Diff: utils/pub/io.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 | « tests/standalone/io/test_runner_test.dart ('k') | utils/pub/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 /// Helper functionality to make working with IO easier. 5 /// Helper functionality to make working with IO easier.
6 library io; 6 library io;
7 7
8 import 'dart:async'; 8 import 'dart:async';
9 import 'dart:io'; 9 import 'dart:io';
10 import 'dart:isolate'; 10 import 'dart:isolate';
(...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 /// [milliseconds] have passed, then the return value completes in the same way. 695 /// [milliseconds] have passed, then the return value completes in the same way.
696 /// However, if [milliseconds] pass before [input] has completed, it completes 696 /// However, if [milliseconds] pass before [input] has completed, it completes
697 /// with a [TimeoutException] with [description] (which should be a fragment 697 /// with a [TimeoutException] with [description] (which should be a fragment
698 /// describing the action that timed out). 698 /// describing the action that timed out).
699 /// 699 ///
700 /// Note that timing out will not cancel the asynchronous operation behind 700 /// Note that timing out will not cancel the asynchronous operation behind
701 /// [input]. 701 /// [input].
702 Future timeout(Future input, int milliseconds, String description) { 702 Future timeout(Future input, int milliseconds, String description) {
703 bool completed = false; 703 bool completed = false;
704 var completer = new Completer(); 704 var completer = new Completer();
705 var timer = new Timer(milliseconds, (_) { 705 var timer = new Timer(new Duration(milliseconds: milliseconds), () {
706 completed = true; 706 completed = true;
707 completer.completeError(new TimeoutException( 707 completer.completeError(new TimeoutException(
708 'Timed out while $description.')); 708 'Timed out while $description.'));
709 }); 709 });
710 input.then((value) { 710 input.then((value) {
711 if (completed) return; 711 if (completed) return;
712 timer.cancel(); 712 timer.cancel();
713 completer.complete(value); 713 completer.complete(value);
714 }).catchError((e) { 714 }).catchError((e) {
715 if (completed) return; 715 if (completed) return;
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 Directory _getDirectory(entry) { 941 Directory _getDirectory(entry) {
942 if (entry is Directory) return entry; 942 if (entry is Directory) return entry;
943 return new Directory(entry); 943 return new Directory(entry);
944 } 944 }
945 945
946 /// Gets a [Uri] for [uri], which can either already be one, or be a [String]. 946 /// Gets a [Uri] for [uri], which can either already be one, or be a [String].
947 Uri _getUri(uri) { 947 Uri _getUri(uri) {
948 if (uri is Uri) return uri; 948 if (uri is Uri) return uri;
949 return Uri.parse(uri); 949 return Uri.parse(uri);
950 } 950 }
OLDNEW
« no previous file with comments | « tests/standalone/io/test_runner_test.dart ('k') | utils/pub/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698