OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 var done = controller.stream.pipe(consumer); | 336 var done = controller.stream.pipe(consumer); |
337 return new Pair<EventSink, Future>(controller.sink, done); | 337 return new Pair<EventSink, Future>(controller.sink, done); |
338 } | 338 } |
339 | 339 |
340 // TODO(nweiz): remove this when issue 7786 is fixed. | 340 // TODO(nweiz): remove this when issue 7786 is fixed. |
341 /// Pipes all data and errors from [stream] into [sink]. When [stream] is done, | 341 /// Pipes all data and errors from [stream] into [sink]. When [stream] is done, |
342 /// the returned [Future] is completed and [sink] is closed if [closeSink] is | 342 /// the returned [Future] is completed and [sink] is closed if [closeSink] is |
343 /// true. | 343 /// true. |
344 /// | 344 /// |
345 /// When an error occurs on [stream], that error is passed to [sink]. If | 345 /// When an error occurs on [stream], that error is passed to [sink]. If |
346 /// [unsubscribeOnError] is true, [Future] will be completed successfully and no | 346 /// [cancelOnError] is true, [Future] will be completed successfully and no |
347 /// more data or errors will be piped from [stream] to [sink]. If | 347 /// more data or errors will be piped from [stream] to [sink]. If |
348 /// [unsubscribeOnError] and [closeSink] are both true, [sink] will then be | 348 /// [cancelOnError] and [closeSink] are both true, [sink] will then be |
349 /// closed. | 349 /// closed. |
350 Future store(Stream stream, EventSink sink, | 350 Future store(Stream stream, EventSink sink, |
351 {bool unsubscribeOnError: true, closeSink: true}) { | 351 {bool cancelOnError: true, closeSink: true}) { |
352 var completer = new Completer(); | 352 var completer = new Completer(); |
353 stream.listen(sink.add, | 353 stream.listen(sink.add, |
354 onError: (e) { | 354 onError: (e) { |
355 sink.addError(e); | 355 sink.addError(e); |
356 if (unsubscribeOnError) { | 356 if (cancelOnError) { |
357 completer.complete(); | 357 completer.complete(); |
358 if (closeSink) sink.close(); | 358 if (closeSink) sink.close(); |
359 } | 359 } |
360 }, | 360 }, |
361 onDone: () { | 361 onDone: () { |
362 if (closeSink) sink.close(); | 362 if (closeSink) sink.close(); |
363 completer.complete(); | 363 completer.complete(); |
364 }, unsubscribeOnError: unsubscribeOnError); | 364 }, cancelOnError: cancelOnError); |
365 return completer.future; | 365 return completer.future; |
366 } | 366 } |
367 | 367 |
368 /// Spawns and runs the process located at [executable], passing in [args]. | 368 /// Spawns and runs the process located at [executable], passing in [args]. |
369 /// Returns a [Future] that will complete with the results of the process after | 369 /// Returns a [Future] that will complete with the results of the process after |
370 /// it has ended. | 370 /// it has ended. |
371 /// | 371 /// |
372 /// The spawned process will inherit its parent's environment variables. If | 372 /// The spawned process will inherit its parent's environment variables. If |
373 /// [environment] is provided, that will be used to augment (not replace) the | 373 /// [environment] is provided, that will be used to augment (not replace) the |
374 /// the inherited variables. | 374 /// the inherited variables. |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
731 const PubProcessResult(this.stdout, this.stderr, this.exitCode); | 731 const PubProcessResult(this.stdout, this.stderr, this.exitCode); |
732 | 732 |
733 bool get success => exitCode == 0; | 733 bool get success => exitCode == 0; |
734 } | 734 } |
735 | 735 |
736 /// Gets a [Uri] for [uri], which can either already be one, or be a [String]. | 736 /// Gets a [Uri] for [uri], which can either already be one, or be a [String]. |
737 Uri _getUri(uri) { | 737 Uri _getUri(uri) { |
738 if (uri is Uri) return uri; | 738 if (uri is Uri) return uri; |
739 return Uri.parse(uri); | 739 return Uri.parse(uri); |
740 } | 740 } |
OLD | NEW |