| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 } |
| OLD | NEW |